Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Stop pipeline without failure (GitOps "empty-commit" commands)

Charles Paul
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 18, 2025

I am implementing a GitOps solution using Bitbucket pipelines but am having difficulties incorporating GitOps commands using empty commits. 

I set up a `default` pipeline that inspects the commit message to execute the GitOps action in order to deploy to specific environments.  There is also a pipeline to handle pull requests to `main`.  The issue is that the default pipeline always runs, but there is no graceful way to prematurely stop this pipeline if a command is not issued.  Take this (paraphrased) example pipeline:


pipelines:
default:
- step:
name: Check GitOps Command
runs-on:
- self.hosted
script:
- export COMMIT_MESSAGE=$(git log --format=%B -n 1 $BITBUCKET_COMMIT)
- if [[ "${COMMIT_MESSAGE,,}" != *"[deploy]"* ]]; then
- echo "STOP_PIPELINE=true" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
- exit 0
- fi
- export ENV=`echo $COMMIT_MESSAGE | cut -d ']' -f2 | xargs`
- echo "ENV=$ENV" >> $BITBUCKET_PIPELINES_VARIABLES_PATH
output-variables:
- ENV
- STOP_PIPELINE
- step:
name: 'Run Deployment'
trigger: manual # The trigger will always activate, unless exit 1 in previous step
script:
- if [ $STOP_PIPELINE ]; then exit 0; fi
- ./deploy_command $ENV
pull-requests:
'**':
- step:
name: 'Check branch and run tests'
script:
- if [ "${BITBUCKET_PR_DESTINATION_BRANCH}" != "main" ]; then printf 'target branch not main, skipping test'; exit; fi
- run_test_command


The `default` pipeline will run on every commit regardless if there is a gitops command in the commit message.  A variable can be set in to prematurely end subsequent steps, but it will not prevent a manual trigger from being activated.

Is there a way to gracefully stop a pipeline without creating a failure event and subsequent notifications?  That or a way to run pipelines for empty commits outside of "default"?

2 answers

0 votes
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 27, 2025

Hi @Charles Paul

Welcome to the community.

Perhaps using an after-script may help in your case.

The idea is to gracefully exit the specific step using the STOP_PIPELINE condition.

Then add your deployment script in the after-script validating the "BITBUCKET_EXIT_CODE" of the actual step.

Regards,
Mark C

0 votes
Aron Gombas
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 19, 2025

I think we were in a slightly similar situation years ago.

As far as I remember, Pipelines decides the "success or failure" state based on the OS level exit code of the last command. And you can maybe do tricks like piping the command output to an empty sink to "swallow" the exit code of the command...

Just a hint.

Charles Paul
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
August 19, 2025

Hi Aron - yeah, the pipeline will stop if a non-zero exit code is issued.  This technique "works" but it causes a pipe failure which results in alerts and clutters the pipeline history with false-negative events.

I also tried to pre-empt execution of other steps by checking for the variable "STOP_PIPELINE" -- this, however, will not prevent a step with a manual trigger from executing and then preventing other pipelines from completing until the step is run.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events