Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fail a script running in Bitbucket Pipelines?

When a pipeline runs a node series of commands, how can I trigger a fail within the pipeline?

I have tried the following:

const failBuild = function(message) {
  console.error('Deploy failed: ', message)
  throw new Error('Deploy failed')
}

I see the "Deploy failed" message, but the pipeline still says "Success".

like image 585
Chris Avatar asked Oct 11 '25 19:10

Chris


1 Answers

Bb Pipelines fail when a command exits with a non-zero exit code. So, if you want the pipeline to fail, you have to make sure the code is not 0.

In your case (note for people reading this later: see comments), you get 0 as exit status, because the throw is executed in a promise, but then catched in the promise’s catch() function – which does neither stop execution nor have any influence on the exit code.

Solution: explicitly throw an error in the catch() function.

like image 145
BlueM Avatar answered Oct 15 '25 08:10

BlueM