Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Defining Conditional Steps Edited

NOTE: this is not much of a question; but a suggestion/request for consideration of new functionality


I want to run some steps only in particular cases.

My expectation would be like:

- step: &do-some-deployemnt
name: Do some Deployment
- echo "this happens only if condition is met"

- step:
- echo "this happens only if condition is met"
when: <condition>
- variables:
- name: VAR_NAME
- step:
<<: *do-some-deployemnt
deployment: Production
when: <condition>
- variables:
- name: VAR_NAME
- step:
<<: *do-some-deployemnt
deployment: Test
when: <condition>
- step:
<<: *do-some-deployemnt
deployment: Production-1
when: <condition>
- step:
<<: *do-some-deployemnt
deployment: Production-2
when: <condition>

for the purpose of clarity, lets say in Bit-Bucket setting we created "deployment variables"

on here

  • pull-requests uses git diff
  • some-custom-pipeline-1 uses "custom variables"
  • some-custom-pipeline-2 uses both "custom variables" and "deployment variables"

now, condition could be anything which evaluates to true/false at the end

when: $(git diff --name-only --diff-filter=AMDR HEAD^ some-directory-or-file) != ""

we have multiple steps, only deploy the one if a deployment variable matches the user input variable

when: ENVIRONMENT_NAME = VAR_NAME # if deployment variable matched custom variable

based on a custom variable input by the user. On example some-custom-pipeline-2, there is 1 test deployment and 2 different production deployments. User might want to deploy Test, or both Productions.

when: VAR_NAME = 'production' # if custom variable matched string


a similar question was asked at:

but this question was routed ONLY to file changes

1 answer

As far as I know steps can not have conditions (e.g. the when in your question, like the when in Ansible probably).

But steps can have a script and within a script you can encode all sort of conditional expressions. So maybe moving the condition into the step could do it in your case already?

maybe I posted the question wrong.

It's less a question, and more a request for possible future functionality

this would be a before script then, which I think should not be necessary as you could do it at the very beginning of the script and exit 0 otherwise. that should work.

a feature request for a when would merely result in a different expression language, not the shell expressions you have as examples in your question.

but I'm not from Atlassian, so just what pops into my limited mind. Someone from Atlassian will also tell you in an answer how/where you can file feature requests.

the difference being

if a step runs, and at the start of the script you implement your conditional, the step still runs. The initial "Build setup" takes place, consumes resources, and shows the step as run..  even if with an exit as it's first command

If the conditional is run before, then if false, the step does not even run. On the case of example some-custom-pipeline-2, either 1 or 2 steps would run, but not all 3. And with some extra logic, if no steps are run in a pipeline, then the entire pipeline might not even run.

And what would be your understanding where the when condition would be executed?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket Pipelines

Bitbucket Pipelines Runners is now in open beta

We are excited to announce the open beta program for self-hosted runners. Bitbucket Pipelines Runners is available to everyone. Please try it and let us know your feedback. If you have any issue...

762 views 15 10
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you