Forums

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

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

Mike Bridge
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!
September 30, 2020

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
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2020

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

0 votes
Mike Bridge
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!
October 5, 2020

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
AUG Leaders

Atlassian Community Events