AzureYAML-Pipeline跳过作业,我不知道为什么
即使我设置了 System.Debug=True,除了“作业被跳过”之外,我没有得到其他信息。字面意思就是这四个字。
我在 Azure Devops 上创建了一个 YAML-Release 管道,它基本上运行这些作业:
- 工作:build_release
- 工作:部署:deploy_test
- 工作:部署:deploy_stage
为了测试行为,我首先只运行前两个作业并部署到 TEST。现在我想部署到 STAGE,但似乎只有当我从头开始/创建新版本时,管道才起作用。但是我现在想要做的是将已经存在的版本从 TEST 部署到 STAGE。当我尝试通过重新运行管道来做到这一点时,Azure 只会跳过所有步骤。为什么会这样?如何避免这种情况并重新运行管道?我没有设置任何条件。
编辑附加信息:
管道结构
trigger:
- release/*
variables:
...
resources:
- repo: self
pool:
vmImage: $(vmImageName)
stages:
- stage: build_release
displayName: 'awesome build'
condition: contains(variables['Build.SourceBranchName'], 'release/')
jobs:
- job: build_release
steps:
...
- stage: deploy_test
displayName: 'awesome test deploy'
jobs:
- deployment: deploy_test
environment: 'test'
strategy:
runOnce:
deploy:
steps:
...
- stage: deploy_stage
displayName: 'awesome stage deploy'
jobs:
- deployment: deploy_stage
environment: 'stage'
strategy:
runOnce:
deploy:
steps:
...
我尝试以两种不同的方式触发它,结果相同(所有内容都被跳过): A. 我创建了一个新版本,它是以前部署的版本的副本。B. 我点击了运行管道。
回答
The issue is caused by the condition condition: contains(variables['Build.SourceBranchName'], 'release/'), which you specified for stage build_release.
When the trigger is set to - release/*. The variable variables['Build.SourceBranchName'] will be evaluated to the branch name after the /.
For example:
If you triggered your pipeline from branch release/release1.0. the value of variables['Build.SourceBranchName'] will be release1.0 instead of release/release1.0. So the condition contains(variables['Build.SourceBranchName'], 'release/') will always be false, which caused the stage build_release to be skipped.
And, if you didnot specify dependency for stage deploy_test and stage deploy_stage, the next stage will depends on the previous stage by default. So these two stages also got skipped, since stage build_release is skipped. This is why you saw all the steps were skipped.
Solution:
Using variable Build.SourceBranch in the condition.
更改条件如下:(发布分支中的 yaml 文件也应更改如下)
- stage: build_release
displayName: 'awesome build'
condition: contains(variables['Build.SourceBranch'], 'release/') #use Build.SourceBranch
注意:如果你 mannaly 触发了你的管道。请确保您选择从发布分支触发管道。或者管道将默认从主分支触发。