我有一個 Azure DevOps YAML 管道,如果我將提交推送到我的 git 主分支,它總是運行。沒關系。
但現在我想使用 git 標記和條件來運行此管道中的特定作業,前提是提交包含特定標記。
如何讓 git 標簽在條件下使用它們?
謝謝轉發
最好的問候馬蒂亞斯
uj5u.com熱心網友回復:
你說的“ if the commit contains a specific tag”是什么意思?
- 如果這意味著從提交創建的 git 標簽:
例如,我有格式為“
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: . . .
- 如果它表示提交訊息中包含的指定關鍵字:
例如,提交訊息包含關鍵字 like 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: . . .
uj5u.com熱心網友回復:
您可以檢查以下管道。它基于標簽觸發,也基于標簽執行特定任務。
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 運行管道時,將執行任務第二個管道。

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/449511.html
標籤:混帐 天蓝色的devops yaml
上一篇:為什么當它涉及兩個檔案夾時,我的沒有沖突的合并提交會顯示在由一個檔案夾過濾的gitlog中,而不是另一個檔案夾?
