azure-pipelines - 根据签出的分支/标签使用不同的 azure 管道模板
问题描述
我们现在正在组织中迁移到 Azure 管道,我们将使用模板机制集中更改构建逻辑。
请参阅下面的当前示例。
name: $(Date:yyyyMMddHHss).$(SourceBranchName).$(Build.SourceVersion)
resources:
repositories:
- repository: build_resources # id for reuse in below script code
type: git # use 'git' for Azure git repository
name: build-resources # repository name
ref: refs/tags/1.1.2
jobs:
- template: build/azure-pipelines-template.yml@build_resources # Template reference
parameters:
projectfolder: 'blabla'
这将始终检查构建模板的特定版本。
我们现在想实现以下几点:当签出分支是“开发”时,将始终使用最新版本的构建模板。但是当我们说一个“发布”分支甚至一个标签正在被构建时,一个固定版本的构建模板应该被使用。
我的想法是在 YAML 中使用一些字符串处理,然后选择不同的存储库资源。但我不确定这在 YAML 中是否可行,以及是否有更好的方法可以推荐给我。
谢谢
解决方案
您可以根据条件从管道 YAML 调用不同的模板。在此示例中,stable.yml YAML 将在运行分支测试时运行。
稳定的.yml
steps:
- script: echo "stable.yml"
实验.yml
steps:
- script: echo "experimental.yml"
YAML 代码:
steps:
- ${{ if eq(variables['Build.SourceBranchName'], 'develop') }}:
- template: experimental.yml
- ${{ if eq(variables['Build.SourceBranchName'], 'release') }}:
- template: stable.yml
请参阅此文档以获取更多详细信息。
推荐阅读
- javascript - How to prevent anyPicker from taking user minutes?
- python - How to slice a cluster from a particular column
- java - Need to parse the JSON ARRAYS that are inside the JSON Object in JAVA
- swift - 使用 MFMessageComposeViewController 快速打开带有文本和 url 的短信应用程序
- java - The executed string value does not match to the hard coded value
- sql-server - Performance of SELECT * in an Inline Table-Valued Function
- google-cloud-platform - 如何使用 TextIO 读取文本文件并返回附加输入字段?
- python-3.7 - 为什么函数不循环,循环输入?
- javascript - Jasmine单元测试,如何触发ngx-modal-dialog的点击事件
- c# - C# bot framework Align checkboxes in adaptive card along a row