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
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.