0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure DevOps Pipelineで別リポジトリへ反映する方法:Repo A→Repo Bの最小構成メモ

0
Posted at

Azure DevOps で 同一レポジトリ内のプルリクエスト&マージではなく、
リポジトリからの別リポジトリへ内容を反映したいことがあります。
今回は取り急ぎの検証として、DevOps Pipeline を使ってレポジトリAの内容をレポジトリBへ反映する方法 を備忘録としてまとめます。

今回はシンプルに、同一プロジェクト内の Repo A → Repo B の同期を対象にしています。
あくまで最小構成のデモになります。

事前準備

今回はデモのため、自身のPCを Agent Pool として使用 しました。

[Organization Settings]>[Pipelines]>[Agent pools]>[Default]の順に進み、
[New Agent]をクリックします。

image.png

今回は Windows 環境だったため、そのまま Download をクリックします。

image.png

ダウンロードした zip ファイルを展開し、
config.cmd を実行して順に設定を進めます。

注意点

  • 個人用アクセストークン(PAT)が必要です
  • 操作者には Default プールの Manage 権限 が必要です
    必要に応じて、管理者に権限付与を依頼してください
    image.png

登録した Agent が Online になっていれば、事前準備は完了です。

image.png

agentをオフにするには
「run.cmd」を開いているターミナル上で Ctrl + C を実行すると停止できます。

image.png

パイプライン作成

[Pipelines]のメニューから
[New Pipeline]をクリックします。

image.png

次に [Azure Repos Git YAML] を選択し、
レポジトリA を選びます。

その後、[Configure] で以下のコードを使用します。


trigger:
- main

pool:
  name: Default   # self-hosted agent のプール名

steps:
- checkout: self
  persistCredentials: true

- script: |
    echo ===== Repo A =====
    hostname
    whoami
    dir

    git config --global user.email "<your-email@example.com>"
    git config --global user.name "Azure Pipeline"

    cd ..
    if exist repoB rmdir /s /q repoB

    git clone https://dev.azure.com/<your-organization>/<your-project>/_git/<your-repo-b> repoB

    robocopy s repoB /MIR /XD .git
    if %ERRORLEVEL% LEQ 3 set ERRORLEVEL=0

    cd repoB
    git add -A
    git commit -m "Sync from Repo A to Repo B" || echo No changes to commit
    git push origin main
  displayName: "Sync Repo A to Repo B"

ご自身の情報に置き換える場所は以下4点です

保存後、Run を実行します。

レポジトリAの内容がレポジトリBに反映されていれば成功です。

Youtubeもやってます!

FabricやDatabricksについて学べる勉強会を毎月開催!

次回イベント欄から直近のMicrosoft Data Analytics Day(Online) 勉強会ページへ移動後、申し込み可能です!

関連記事

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?