简体   繁体   English

在失败的任务上继续执行Azure Pipeline

[英]Continue Azure Pipeline on failed task

I have a task that runs Cypress: 我有一个运行赛普拉斯的任务:

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

And I've set the ErrorActionPreference to continue . 我已经设定ErrorActionPreferencecontinue But when my Cypress fails: 但是当我的赛普拉斯失败时:

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

The next task is canceled and the release failed. 下一个任务被取消,发布失败。 How do I continue the release even Cypress failed, and is it possible to give a boolean a true/false value based on the Cypress task result? 即使Cypress失败,我如何继续发行,是否可以根据Cypress任务结果为布尔值提供true / false值?

you can put a condition on the subsequent tasks to work even if previous tasks failed. 即使先前的任务失败,您也可以为后续的任务设置条件。

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/zh-cn/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 https://docs.microsoft.com/zh-cn/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

The ErrorActionPreference option is used to determine whether to continue to execute rest code instead of task. ErrorActionPreference选项用于确定是否继续执行剩余代码而不是任务。 So, with continue value for ErrorActionPreference , the task will execute next line code of your script even through current line code throws error, unless you call exit . 因此,使用ErrorActionPreference的 continue ,该任务将执行脚本的下一行代码,即使当前行代码抛出错误也将执行该脚本,除非您调用exit

For your requirement, you are using release pipeline (it is UI designer), and you want to continue to run whole release, so, you just need to check Continue on error option: 根据您的需求,您正在使用发布管道(它是UI设计器),并且您想继续运行整个发布,因此,您只需要选中“错误继续”选项:

在此处输入图片说明

如果即使Cypress任务失败,也要继续发布,只需将以下行添加到Cypress任务中:

continueOnError: true 

The argument "ErrorActionPreference" is used to setting whether the code inside this script execute with errors or not, it can't control the next task. 参数“ ErrorActionPreference”用于设置此脚本中的代码是否执行有错误,它无法控制下一个任务。

You can add a condition in the end of the subsequent tasks. 您可以在后续任务的末尾添加条件。

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

Or you can add an argument setting to the error task. 或者,您可以将参数设置添加到错误任务。

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

Hope this can help you! 希望这可以帮到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM