【问题标题】:Continue Azure Pipeline on failed task在失败的任务上继续 Azure Pipeline
【发布时间】:2019-07-07 20:46:36
【问题描述】:

我有一个运行 Cypress 的任务:

-ErrorAction SilentlyContinue
cd $(System.DefaultWorkingDirectory)/_ClientWeb-Build-CI/ShellArtifact/
npx cypress run

我已将ErrorActionPreference 设置为continue。但是当我的赛普拉斯失败时:

##[error]PowerShell exited with code '1'.

下一个任务被取消,发布失败。即使 Cypress 失败,我如何继续发布,是否可以根据 Cypress 任务结果为布尔值提供真/假值?

【问题讨论】:

  • 嘿伙计,考虑接受其中一个答案

标签: azure azure-devops azure-pipelines


【解决方案1】:

如果你想在 Cypress 任务失败的情况下继续发布,只需在 Cypress 任务中添加这一行:

continueOnError: true 

【讨论】:

    【解决方案2】:

    即使之前的任务失败,您也可以为后续任务设置条件。

    jobs:
    - job: Foo
    
      steps:
      - powershell: |
          your code here
      - script: echo Hello!
        condition: always() # this step will always run, even if the pipeline is cancelled
    
    - job: Bar
      dependsOn: Foo
      condition: failed() # this job will only run if Foo fails
    

    https://docs.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#job-status-functions
    https://docs.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

    【讨论】:

      【解决方案3】:

      参数“ErrorActionPreference”用于设置此脚本中的代码执行是否出错,不能控制下一个任务。

      您可以在后续任务的末尾添加条件。

      condition: always() # this step will always run, even if the pipeline is cancelled

      或者您可以为错误任务添加参数设置。

      continueOnError: true # 'true' if future steps should run even if this step fails; defaults to 'false'

      希望对你有帮助!

      【讨论】:

        【解决方案4】:

        ErrorActionPreference选项用于判断是否继续执行rest code而不是task。因此,使用 ErrorActionPreference 的 continue value,即使当前行代码抛出错误,任务也会执行脚本的下一行代码,除非您调用 exit.

        根据您的要求,您正在使用发布管道(它是 UI 设计器),并且您想继续运行整个发布,因此,您只需选中 Continue on error 选项:

        【讨论】:

        • 我们应该在 ErrorActionPreference 中使用什么 .: stop 或 continue ..?如果我选择停止我的任务部分成功,它会跳过我的下一个任务,即错误创建逻辑和我的发布成功的最后阶段。
        猜你喜欢
        • 1970-01-01
        • 2020-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-30
        • 1970-01-01
        • 2022-08-06
        • 2021-04-20
        相关资源
        最近更新 更多