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

Parametrized anchors in pipelines

I could reuse lots of pipeline code if I could parametrize it even if through ENV variable.

So I could define an anchor like

- step: &Test
name: Test
script: echo $MySetting

 And then I could reuse it with my setting

- parallel:
- step:
<<: *Test
before-script: MySetting=Test1
- step:
<<: *Test
before-script: MySetting=Test2

Is something like this available?

1 answer

0 votes

@Arturs Sosins hello! Look at one of the examples how you can define your steps .

With definitions keyword usually services are defined, I don't find official doc how you can define steps like this and sometimes it might fail for you.

Use the structure as you can see in the example above.

Regards, Galyna

so I think this way you can define multiple steps per branch
but it would not allow me to parametrize the same step in different branches, would it?

@Arturs Sosins yes, you can define those steps you define before in any branch following guide for pipeline configuration. You could run also as many time as you need your step , referring like this

- <<: *test1
- <<: *test2
- <<: *test1
- <<: *test-integration
- <<: *test1

You can have different workflows.

Sorry, still don't get it
It is not about the branches, but about the ability to change the behavior of step based on outside variable
So for example I want test1 step to behave a bit differently on the master branch than qa branch.
I know I can use the branch variable for this case
But what if I want to do the same on the manual custom pipeline, there is no way to define variable outside of step, is it?

@Arturs Sosins I've got your point. I think we do not have such ability right now, if you want test to execute different workflows.

Such tests could be executed in different ways on different branches only if you, for example create several deployments and deployment variables and use different deployments for master and qa.

But if it goes deeper to logic of test workflow and cannot be customized just via deployment variables, it will not work.

For example let your test depends on deployment variable ENVIRONMENT and this variable is different in different deployment environments, for example, ENVIRONMENT can be 'production', 'qa'. And based on this decision your step is taking actions depending on this variable.

BUT if your test on one branch should execute unit tests, for example and on another branch do some integration tests and needs specific actions for that, I guess, you cannot unify such workflow for different branches.

Or do some thing like this:

if ENVIRONMENT = 'prod' then ...

if ENVIRONMENT = 'qa' then....

But this solution would be silly and it is better to create different steps.

Just keep in mind that you have only ability to have flexible step only due to different variables customized (deployment, repository variables). I believe this will help you to write a proper pipeline.

Suggest an answer

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

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

117 views 2 4
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