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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

 And then I could reuse it with my setting

pipelines:
branches:
master:
- 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 https://bitbucket.org/atlassian/aws-elasticbeanstalk-deploy/src/0545b1d8703a8ebe471cc3bf772cd56796f0e91f/bitbucket-pipelines.yml#lines-102 .

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

Hello,
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

branches:
master:
- <<: *test1
- <<: *test2
- <<: *test1
qa-*:
- <<: *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
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,323 views 0 3
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