在失败的任务上继续 Azure Pipeline

Pet*_*sma 3 azure azure-devops azure-pipelines

我有一个运行 Cypress 的任务:

-ErrorAction SilentlyContinue
cd $(System.DefaultWorkingDirectory)/_ClientWeb-Build-CI/ShellArtifact/
npx cypress run
Run Code Online (Sandbox Code Playgroud)

我已经设定的ErrorActionPreferencecontinue。但是当我的 Cypress 出现故障时:

##[error]PowerShell exited with code '1'.
Run Code Online (Sandbox Code Playgroud)

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

Sha*_*zyk 12

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

continueOnError: true 
Run Code Online (Sandbox Code Playgroud)


sta*_*SFT 8

ErrorActionPreference选项用于确定是否继续执行其余代码而不是另一个任务。因此,使用ErrorActionPreference的continue,即使当前行抛出错误,任务也将执行脚本的下一行代码,除非您显式调用exit

根据您的要求,您正在使用发布管道(使用 UI 设计器)并且希望继续运行整个版本,因此,您只需要选中“出错时继续”选项:

在此输入图像描述


小智 6

参数“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'

希望这可以帮到你!


4c7*_*b41 5

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

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
Run Code Online (Sandbox Code Playgroud)

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