【发布时间】:2021-04-30 12:05:39
【问题描述】:
我想通过变量获得多阶段管道中前一阶段的结果。
我知道可以使用依赖对象通过依赖对象访问前一阶段的结果(请参阅:Expressions in Azure Pipelines)。
例如,如果我有一个名为“deploy”的前一个阶段,那么我可以将结果作为另一个阶段的条件来访问,例如:
condition: in(dependencies.deploy.result, 'Skipped')
这完全符合预期,但是,我想在 condition 之外使用此变量,即在 bash 任务中回显阶段结果,或将其添加到工作项描述中。
但是,在条件之外,这似乎是不可能的。如果我想将结果用作变量,或者将结果用作条件的 if 查询,它似乎不起作用。例如下面的代码块,testString 和 anotherTestString 最终都是空字符串:
- stage: afterDeploy
dependsOn:
- deploy
condition: in(dependencies.deploy.result, 'Skipped')
variables:
testString: $[dependencies.deploy.result]
${{ if in(dependencies.deploy.result, 'Skipped') }}:
anotherTestString: "Skipped"
我还尝试使用不同的方式来访问变量,即${{ dependencies.deploy.result }}、$(dependencies.deploy.result),或者使用 stageDependency 而不是依赖关系 (stageDependencies.deploy.result)。
有没有直接访问上一阶段结果的好方法,还是我必须求助于通过the REST API 获取结果?或者,我可以添加一个额外的任务,将状态结果导出为新变量。这两种解决方案都不是最优的,因为阶段结果在技术上可以通过依赖对象获得......
【问题讨论】:
标签: azure azure-devops azure-pipelines