Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continue build after script fails in Azure DevOps

In my Azure DevOps build task I run a Cypress test. If the test fails the build is canceled. But I want to run another task after Cypress the publishes the test results.

I've tried it with this task in my pipeline.yml file:

- task: PowerShell@2
  inputs:
    targetType: "inline"
    script: "yarn test:cypress"
    errorActionPreference: "continue"
  displayName: "start server and run cypress"

But this doesn't seem to have any effect.

I've tried add -ErrorAction 'Continue' to to script"

"start": "npm-run-all -s build:shared-web run:shell",
"cy:run": "cypress run -ErrorAction 'Continue'",
"test:cypress": "start-server-and-test start http://localhost:3000 cy:run"

But this fails with:

error: unknown option: -E

It looks like Cypress is seeing the ErrorAction as a Cypress parameter.

So what's the correct way of continuing a build if a task fails?

like image 836
Peter Boomsma Avatar asked Jun 18 '26 19:06

Peter Boomsma


1 Answers

You can add to the task this:

continueOnError: true

Now the build will keep running even the tests will fail.

If you want to fail the build if the tests failed but you want to run only one task to publish the results, you can add this to the publish tests task:

condition: always()

Now the publish task will be running always, even the tests are failed and the build canceled/failed.

like image 179
Shayki Abramczyk Avatar answered Jun 20 '26 10:06

Shayki Abramczyk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!