You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
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?
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:
- echo export BuildTag="v1.2-1" > 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.