只有在前一步成功的情况下才运行Azure管道模板。

huangapple go评论65阅读模式
英文:

only run azure pipeline template if previous step succeeded

问题

  • ${{ if and(in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues'), eq(parameters.deployToDevServer, true)) }}:
    • template: Templates/push-files-to-release-artifacts-repo.yml
      parameters:
      releaseArtifactsRepoPath: $(Build.Repository.LocalPath)/ReleaseArtifacts
英文:

Is there a way to run a template if and only if the previous step in the pipeline job completed successfully and anther condition is met as well? Here's what I tried:

- ${{ if and(in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues'), eq(parameters.deployToDevServer, true)) }}:
  - template: Templates/push-files-to-release-artifacts-repo.yml
    parameters:
      releaseArtifactsRepoPath: $(Build.Repository.LocalPath)/ReleaseArtifacts

But the step doesn't execute at all. I also tried using the succeeded() conditional but it wouldn't validate the YAML. To sum it up, I am trying to conditionally run this template based on whether the parameters.deployToDevServer value is true and the previous step succeeded.

答案1

得分: 2

这种方式是不可能的。因为您在此处混合了编译时 (${{ }}) 和运行时 (variables['Agent.JobStatus']) 表达式 - ${{ if and(in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues'), eq(parameters.deployToDevServer, true)) }}:

整个表达式在编译时进行评估,然后 variables['Agent.JobStatus'] 只是空的。您需要使用条件来在模板中跳过您的阶段/作业/步骤。但这必须在模板中完成。

英文:

This is not possible to do this in this way. Because you are mixing compile-time (${{ }}) and run-time (variables['Agent.JobStatus']) expressions here - ${{ if and(in(variables['Agent.JobStatus'], 'Succeeded', 'SucceededWithIssues'), eq(parameters.deployToDevServer, true)) }}:

The whole expression is evaluated at compile and then variables['Agent.JobStatus'] is just empty. You need to use conditions to skip your stage/job/step in your template. But it has to be done in the template.

huangapple
  • 本文由 发表于 2023年7月11日 06:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76657630.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定