LoginSignup
0
0

Azure Pipelines でブランチ別にパイプライン YAML を外出しにしてみた

Posted at

例えば main ブランチと develop ブランチがあったとします。ブランチ別に CI で実行する内容を変えたい場合、条件分岐して記述すると思います。そうするとパイプライン YAML 内のインデント階層が深くなったり、単純に行数が長くなったり段々と扱いづらくなります。そこで今回は、ブランチ別にパイプライン YAML を外出しにする検証を行ってみました。

検証用パイプライン YAML の準備

Azure Pipelines から呼び出される YAML

azure-pipelines.yml
trigger:
  - main
  - develop

pool:
  vmImage: ubuntu-latest

steps:
- script: |
    echo common
  displayName: 'common step'
- ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
  - template: azure-pipelines-main.yml
- ${{ if eq(variables['Build.SourceBranchName'], 'develop') }}:
  - template: azure-pipelines-develop.yml

main ブランチ用 YAML

azure-pipelines-main.yml
steps:
- script: |
    echo main
  displayName: 'main step'

develop ブランチ用 YAML

azure-pipelines-develop.yml
steps:
- script: |
    echo develop
  displayName: 'develop step'

検証結果

main と develop ブランチのパイプライン実行履歴
azure-pipelines-template-01.png

common step と main step の実行を確認
azure-pipelines-template-02.png

common step と develop step の実行を確認
azure-pipelines-template-03.png

参考

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