32

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. 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?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
Peter Boomsma
  • 8,851
  • 16
  • 93
  • 185

4 Answers4

58

If you want to continue the release even the Cypress task failed, just add to the Cypress task this line:

continueOnError: true 
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
26

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://learn.microsoft.com/en-us/azure/devops/pipelines/process/expressions?view=azure-devops#job-status-functions
https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml

4c74356b41
  • 69,186
  • 6
  • 100
  • 141
14

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.

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!

Rongdan
  • 166
  • 3
8

The ErrorActionPreference option is used to determine whether to continue to execute rest code instead of task. 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.

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:

enter image description here

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • 1
    what we should use in ErrorActionPreference .: stop or continue ..? it i select stop my task partially successed and it skip my next task which is for bug creation logic and the final stage my release is success. – Gaurav Joshi Oct 28 '20 at 00:47