英文:
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
- template: Templates/push-files-to-release-artifacts-repo.yml
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论