Azure管道定义用于不同管道任务、步骤等的变量和条件。定义以下YAML管道时,仅当变量isValidReleaseBuild
计算的组合条件为true
时,才应执行步骤ReleaseOnlyScript
。在Azure管道开发运营站点中,定义了变量BuildType
并将其设置为release
。
variables:
- name: isValidReleaseBuild
value: $[and(eq(variables['BuildType'], 'release'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))]
steps:
- script: |
echo "BuildType: $(BuildType)"
echo "SourceBranch: $(Build.SourceBranch)"
echo "ReleaseBuild: $(isValidReleaseBuild)"
displayName: 'Buildinfo'
- ${{ if eq(variables['isValidReleaseBuild'], true) }}:
- script: |
echo "YEAH its a Release!"
displayName: 'ReleaseOnlyScript'
运行管道时,只执行脚本BuildInfo
,输出如下。
BuildType: release
SourceBranch: refs/tags/v1.0.0
ReleaseBuild: True
为什么不执行ReleaseOnlyScript
?
**更新:**感谢Alex AIT的回答,我修改了管道如下,它现在按预期工作。
variables:
- name: isValidReleaseBuild
value: $[and(eq(variables['BuildType'], 'release'), startsWith(variables['Build.SourceBranch'], 'refs/tags/v'))]
jobs:
- job: check_cicd
steps:
- script: |
echo "BuildType: $(BuildType)"
echo "SourceBranch: $(Build.SourceBranch)"
echo "ReleaseBuild: $(isValidReleaseBuild)"
if [ "$(isValidReleaseBuild)" = "True" ]; then
echo "##vso[task.setvariable variable=ValidBuild;isOutput=true]True"
else
echo "##vso[task.setvariable variable=ValidBuild;isOutput=true]False"
fi
name: buildinfo
- job: release_cicd
dependsOn: check_cicd
condition: eq(dependencies.check_cicd.outputs['buildinfo.ValidBuild'], 'True')
steps:
- template: build-release.yml
1条答案
按热度按时间bwleehnv1#
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml
您必须在步骤中使用
condition
,而不是在开头使用表达式。