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
script: echo $MySetting
And then I could reuse it with my setting
Is something like this available?
@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.
@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.
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...
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