Azure DevOps YAML 管道:添加 Git 基于标签的条件
Azure DevOps YAML Pipelines: Add Git Tag based condition
我有一个 Azure DevOps YAML 管道,如果我将提交推送到我的 git 主分支,它总是 运行s。没关系。
但现在我想使用 git 标签和条件来 运行 此管道中的特定作业,仅当提交包含特定标签时。
如何获取 git 标签以在条件中使用它们?
谢谢转发
最好的问候马蒂亚斯
您可以检查以下管道。它是根据标签触发的,也是根据标签执行特定任务的。
trigger:
tags:
include:
- release.*
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- script: echo this pipeline was triggered from the first pipeline
displayName: 'Second pipeline'
condition: eq(variables['Build.SourceBranch'], 'refs/tags/release.v5')
当运行带有release.v4的管道时,任务第二个管道被跳过。
当运行带有release.v5的流水线任务第二流水线执行时
“if the commit contains a specific tag
”是什么意思?
- 如果它表示从提交创建的 git 标签:
例如,我的标签格式为'release-xxx
'。
当标记创建为格式“release-xxx
”时,要运行管道中的特定作业,您可以设置YAML 管道如下所示。您可以使用变量 Build.SourceBranch
获取触发当前管道 运行.
的 branch/tag 名称
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:
. . .
- 如果是commit message中包含的指定关键字:
例如,提交消息包含关键字,如'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:
. . .
我有一个 Azure DevOps YAML 管道,如果我将提交推送到我的 git 主分支,它总是 运行s。没关系。
但现在我想使用 git 标签和条件来 运行 此管道中的特定作业,仅当提交包含特定标签时。
如何获取 git 标签以在条件中使用它们?
谢谢转发
最好的问候马蒂亚斯
您可以检查以下管道。它是根据标签触发的,也是根据标签执行特定任务的。
trigger:
tags:
include:
- release.*
pool:
vmImage: ubuntu-latest
steps:
- script: echo Hello, world!
displayName: 'Run a one-line script'
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- script: echo this pipeline was triggered from the first pipeline
displayName: 'Second pipeline'
condition: eq(variables['Build.SourceBranch'], 'refs/tags/release.v5')
当运行带有release.v4的管道时,任务第二个管道被跳过。
当运行带有release.v5的流水线任务第二流水线执行时
“if the commit contains a specific tag
”是什么意思?
- 如果它表示从提交创建的 git 标签:
例如,我的标签格式为'
release-xxx
'。当标记创建为格式“
的 branch/tag 名称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: . . .
- 如果是commit message中包含的指定关键字:
例如,提交消息包含关键字,如'
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: . . .