Mat*_*rth 1 git yaml azure-devops
我有一个 Azure DevOps YAML 管道,如果我将提交推送到 git 主分支,该管道始终运行。没关系。
但现在我想仅当提交包含特定标签时才使用 git 标签和条件来运行此管道中的特定作业。
如何让 git 标签在某种条件下使用它们?
谢谢你在转发
最好的问候马蒂亚斯
你说的“”是什么意思if the commit contains a specific tag?
例如,我有类似格式“ release-xxx”的标签。
要在创建格式为“ release-xxx”的标签时在管道中运行特定作业,您可以设置 YAML 管道,如下所示。您可以使用该变量Build.SourceBranch来获取触发当前管道运行的分支/标签名称。
trigger:
branches:
include:
- main
tags:
include:
- 'release-*'
pool:
vmImage: windows-latest
jobs:
- job: A
displayName: 'JobA'
steps:
. . .
# JobB only runs when the pipeline is triggered by the tags like as the format 'release-xxx'.
- job: B
displayName: 'JobB'
condition: contains(variables['Build.SourceBranch'], 'refs/tags/release-')
steps:
. . .
Run Code Online (Sandbox Code Playgroud)
例如,提交消息包含关键字“as release-xxx”。
要在提交消息包含“ ”等关键字时在管道中运行特定作业release-xxx,您可以设置 YAML 管道,如下所示。您可以使用该变量Build.SourceVersionMessage来获取提交消息。
trigger:
branches:
include:
- main
pool:
vmImage: windows-latest
jobs:
- job: A
displayName: 'JobA'
steps:
. . .
# JobB only runs when the commit message contains the keyword like as 'release-xxx'.
- job: B
displayName: 'JobB'
condition: contains(variables['Build.SourceVersionMessage'], 'release-')
steps:
. . .
Run Code Online (Sandbox Code Playgroud)