Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to stop early an stop with a success status

awerlang April 13, 2019

I have a step that builds and deploys my app, like this:




Pushing to the repo, an application version is built and deployed. The thing is when the branching off that branch, this pipeline runs again, as designed. This is somewhat troublesome because the deploy script fails (using the same version id). To avoid unnecessary work, I added a check in the build script, which errors when in this situation.


Question: how to avoid running additional scripts in the step, at the same time marking the pipeline as successful, so no email is sent because a failure?

Edit: Also, skip every automatic step after that point.

Thanks in advance!

1 answer

1 vote
Jimmy Seddon
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 13, 2019

Hi André,

While I haven't done this in BitBucket Pipelines (we use Bamboo) I still think the concepts are transferable.  First, as a part of the script I pass in the system variable for the BitBucket Branch i believe in pipelines this is: 'BITBUCKET_BRANCH'

I then wrap the './deploy' portion of the script in an if statment so that it is only executed when we want it to run.  Instead of throwing an error we simply don't execute the deployment when we don't want it to run and that will return a successful result.

I hope that helps!


awerlang April 18, 2019

Hi, yes that's helpful, well at least to understand the problem better.

I guess (haven't tried) I could do this in the beginning of the step's script:

my_command || { echo 'my_command failed' ; exit 0; }

But then the next step would execute normally. I could repeat the command on every step, but in the next step the command would always fail. I would have to set up an artifact to signal the next step not to run.

LanceRushing February 17, 2024

You could check for the file with [[ -f file.txt ]] && exit 0 || echo "continuing..."

Or in my example below try to execute the command I want installed.


- step:
name: 'install files into /usr/local and cache it'
- usr-local-dir
- aws --version && exit 0 || echo "Installing aws-cli";
- curl "" -o ""
- unzip
- ./aws/install --bin-dir /usr/local/bin --install-dir /usr/local/aws-cli --update

Suggest an answer

Log in or Sign up to answer
AUG Leaders

Atlassian Community Events