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

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

Can I use a expression based on the branch name as a trigger value in bitbucket pipeline config?

I have a long step that I would like to trigger automatically from the `staging` and `dev` branch, but manually in prod.

I have this:

branches:
'{dev,staging,prod}':
- step:
name: Ship It!
trigger: manual

I was wondering if I could do something like this:

branches:
'{dev,staging,prod}':
- step:
name: Ship It!
# pseudocode
trigger: ${ $BITBUCKET_BRANCH=="prod" ? "manual" : "automatic" }

... or is there a better way to do this?

2 answers

1 accepted

0 votes
Answer accepted

Hi Mike and welcome to the community!

I'm afraid that syntax like the one you suggested is not possible.

I believe the simplest way to achieve what you want would be to define an automatic step for dev and staging branches only, like this:

pipelines:
  branches:
    '{dev,staging}':
      - step:
          script:
            - ...

In this case, a build will run automatically for every new commit in dev and staging branch.

No build will run automatically for every new commit in prod branch.

However, if you open a commit of the prod branch in Bitbucket UI, you can select the option Run pipeline (at the right side of the page) and then select to run the pipeline branches: {dev,staging} for this commit.

Is this something that works for you?

Kind regards,
Theodora

Yes, it sounds like that would work, although I may just extract the whole prod pipeline and just change that one variable there.

Ultimately it might be a nice feature to have simple expression handling so you can generate strings inside yaml values with a simple templating language.  

Suggest an answer

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

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,717 views 10 16
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