Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,293,730
Community Members
 
Community Events
165
Community Groups

Setting variables from within pipeline step

Hello,

 

I have the following use case for bitbucket pipelines:

- i am building tags using a convention glob pattern, like "v?.?-*"

- my build scripts need to extract the first part as well as the second part of the glob (eg: the "?.?" as well as the "*")

 

I'm not sure if Pipelines provides a way to extract glob patterns as provided into variables available at run time, however I can do that manually via "sed". In thise case though, I would like to execute an initial step that performs splitting the current tag into its components and setting them into variables to be available for the following steps.

 

I know that Github actions allows one to set variables at runtime in a step so that they are available to subsequent steps. How can this be done with pipelines?

 

thanks

1 answer

0 votes

Hi Andrei and welcome to the community!

It is possible to set variables at runtime for custom pipelines only. The variables you set for a custom pipeline will be available for all steps of that pipeline.

You can see an example in our documentation:

The custom pipeline in the example has only one step, but its variables will be available to any other steps you add to that pipeline.

Custom pipelines do not run automatically, they can only be triggered manually or scheduled from the Bitbucket Cloud interface.

 

If you don't want to use custom pipelines and you use ones running e.g. on tags, then you can pass variables from one step to the next one as follows:

In the first step, save these variables in an env file and define this file as an artifact:

- step:
script:
- echo export BuildTag="v1.2-1" > build.env
artifacts:
- build.env

In the next step, you can source this file using a command like the following:

- source build.env

and then you'll be able to use any variables you have defined in that file. With this solution you cannot provide the value of the variable at runtime before the build starts, this is going to work only if you can determine the value programmatically in the script and then assign it to the variable.

We have a feature request to allow users to define variables that can be shared across all steps in the yml file:

You can vote for that feature request if it's something you'd be interested in and add yourself as a watcher if you'd like to get notified via email on updates.

If you have any questions, please feel free to let me know.

Kind regards,
Theodora

Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,112 views 2 9
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