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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,456,500
Community Members
 
Community Events
176
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

Atlassian Community Events