azure pipelines.yml在工作中,仅在上一个步骤失败时运行下一步
目前,我们在我的azure pipelines.yml中有以下代码,我们只想在Sonarqube_publish失败时才能运行Sonarqube_publish_retry。尝试在Sonarqube_publish_retry步骤中使用条件添加条件:Failed()
,但它无法正常工作。有什么想法吗?
stages:
- stage: SonarQube_Scan
jobs:
- job: SonarQube
- task: SonarQubePublish@5
continueOnError: true
displayName: 'Publish SonarQube results'
name: 'sonarqube_publish'
inputs:
pollingTimeoutSec: '300'
- task: SonarQubePublish@5
displayName: 'Retry Publish SonarQube results'
name: 'sonarqube_publish_retry'
inputs:
pollingTimeoutSec: '300'
Currently we have below code in my azure-pipelines.yml, We want to run sonarqube_publish_retry only when sonarqube_publish is failed. Tried adding a condition in the sonarqube_publish_retry step with condition: failed()
but it is not working as expected. Any thoughts?
stages:
- stage: SonarQube_Scan
jobs:
- job: SonarQube
- task: SonarQubePublish@5
continueOnError: true
displayName: 'Publish SonarQube results'
name: 'sonarqube_publish'
inputs:
pollingTimeoutSec: '300'
- task: SonarQubePublish@5
displayName: 'Retry Publish SonarQube results'
name: 'sonarqube_publish_retry'
inputs:
pollingTimeoutSec: '300'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当使用
continonError
,并且步骤引发错误时,将作业状态设置为cactionedwithissues
。如您在 docs ,成功的Withissues
状态将不由failed()
,但由<代码>成功()函数,这就是您的代码不起作用的原因。相反,在这种情况下,请检查agent.jobstatus
变量是否等于cactoredwithissues
:When using
continueOnError
, and the step throws an error, the job status is set toSucceededWithIssues
. As you can see in the docs, theSucceededWithIssues
status will not be picked up by the by thefailed()
but by thesucceeded()
function, that's why your code doesn't work. Instead, in the condition, check theAgent.JobStatus
variable whether it equals toSucceededWithIssues
:多亏了 @DavidCox88,我添加了RetrycountonstaskFailure字段,并且效果很好。
Thanks to @DavidCox88, I have added retryCountOnTaskFailure field and it works perfectly.