もろもろ

もろもろ書いていきます。気軽にコメントください^_^

ソースコード用リポジトリとパイプライン用リポジトリを分けるには

最近プライベートでは Azure DevOps を触っています。
業務では GitLab + Jenkins を使っているのですが、結構違いがあって面白いです。
例えば、GitLab では複数プロジェクトをグループでまとめて管理でき、グループ内のプロジェクトを横断するボードを作成することができます。
一方、Azure DevOps では複数プロジェクトを横断するボードは作成できないのですが、代わりに一つのプロジェクトに複数のリポジトリを持たせることができます。

これを利用して、一つのプロジェクト内にソースコードリポジトリとパイプライン用リポジトリを分けて持たせることができます。
ただし、残念ながら現状、この使い方に対しての完全なサポートは得られないようです。
特にトリガーが別リポジトリの変更を検出できないようで、例えばパイプライン用リポジトリに配置した、

resources:
  repositories:
  - repository: main
    type: git
    name: Project1/Repository1
    trigger:
    - master

stages:
- stage: Stage1
  jobs:
  - job: Job1
    steps:
    - checkout: main
    - task: xxx

といった YAML、或いは、

resources:
  repositories:
  - repository: main
    type: git
    name: Project1/Repository1

trigger:
- master@main

stages:
- stage: Stage1
  jobs:
  - job: Job1
    steps:
    - checkout: main
    - task: xxx

といった YAML で、ソースコードリポジトリの変更をトリガーにパイプラインを実行して欲しいところなのですが、これらは機能しません。

そうなると、せいぜいジョブ記述をテンプレートとしてパイプライン用リポジトリに格納しておくくらいしかできません。

azure-pipelines-master-template.yml@pipelines

stages:
- stage: Stage1
  jobs:
  - job: Job1
    steps:
    - task: xxx

ソースコードリポジトリにはトリガーとテンプレート参照を記述した YAML を格納する必要があります。

azure-pipelines-master.yml@main

resources:
  repositories:
  - repository: pipelines
    type: git
    name: Project1/PipelinesRepository

trigger:
- master

stages:
- template: azure-pipelines-master-template.yml@pipelines

ソースコードリポジトリはブランチがどんどん派生していきますので、この使い方ではトリガーを変更することになったとき一斉に適用することができません。
それでもジョブ記述は分離できるので恩恵はあるのですが、不完全さは否めません。

幸い、別リポジトリの変更を検出する機能はロードマップ上 2020 Q2 (4月~6月) のリリースを予定しているようなので、もう少しの辛抱です。

ROADMAP ITEM: 1454026

  • State: In Progress
  • Reason: Moved to state In Progress
  • Area: AzureDevOpsRoadmap\Pipelines\Build
  • Iteration: AzureDevOpsRoadmap\2020 Q2

    Description:

    At present, you can trigger a pipeline from changes made in a single repository. This will bring in support for triggering pipelines based on changes made in one of multiple repositories. This is useful, for instance, if you manage your code in one repository and the YAML file in a different repository. Commits and work items will be computed based on all the sourced repositories.

https://dev.azure.com/mseng/AzureDevOpsRoadmap/_workitems/edit/1454026