azure pipelines.yml在工作中,仅在上一个步骤失败时运行下一步

发布于 2025-02-01 18:10:03 字数 610 浏览 6 评论 0原文

目前,我们在我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海夕 2025-02-08 18:10:03

当使用continonError,并且步骤引发错误时,将作业状态设置为cactionedwithissues。如您在 docs 成功的Withissues状态将failed(),但由<代码>成功()函数,这就是您的代码不起作用的原因。相反,在这种情况下,请检查agent.jobstatus变量是否等于cactoredwithissues

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'
      condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues')
      inputs:
        pollingTimeoutSec: '300'

When using continueOnError, and the step throws an error, the job status is set to SucceededWithIssues. As you can see in the docs, the SucceededWithIssues status will not be picked up by the by the failed() but by the succeeded() function, that's why your code doesn't work. Instead, in the condition, check the Agent.JobStatus variable whether it equals to SucceededWithIssues:

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'
      condition: eq(variables['Agent.JobStatus'], 'SucceededWithIssues')
      inputs:
        pollingTimeoutSec: '300'
記柔刀 2025-02-08 18:10:03

多亏了 @DavidCox88,我添加了RetrycountonstaskFailure字段,并且效果很好。

Thanks to @DavidCox88, I have added retryCountOnTaskFailure field and it works perfectly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文