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've split my deployment into two steps, one step for building + deploying code and several other steps, which run in parallel, to run some commands needed for deployments against different databases.
What I'd like to do is set some environmental variables at the deployment level and use them as environmental variables in steps that are not part of the deployment as we unfortunately cannot have multiple steps in a single deployment. How would I go about this?
I'd like to use environmental variables set at a deployment level in steps not part of that deployment.
Hi @Neil Nand
I'm not sure if I really got what is your intent with this configuration.
Sorry for the questions, I just want to understand better your scenario to see if I can come with an option for you to move forward.
Hello @Daniel Santos and thanks for the reply.
So the problems I'm trying to solve are:
* Current I'm using repository variables and an export command like the following but as these environmental variables are deployment environment specific it feel like it should be kept there and so I don't have such a large list of environmental variables that are both generic and for each deployment environment.
* That export code above is needed in many steps which is making the bitbucket-pipelines.yml file quite long and I'm looking for ways to trim it down.
* Currently these variables are triggered automatically as part of a branch pipeline. In this pipeline unit tests are run, then code deployed to server then the parallel steps to run commands are run on that environments DB and this is where I'm looking to use the deployment environmental variables.
Currently the setup I've got using the repository environmental variables works but I'm looking for ways to tidy this all up a little.
Hi @Neil Nand
Thank you for sharing! Now I have a better perspective of what you are trying to achieve.
Variables from deployments are limited to their step as you already noticed, but there is a way to transfer them via artifacts.
In the following example, the variables VAR1 and VAR2 are declared in the deployment section:
- echo "I'm building"
name: Deployment step
- echo "export VAR1=\"$VAR1\"" >> variables
- echo "export VAR2=\"$VAR2\"" >> variables
- . variables
- echo "$VAR1"
- . variables
- echo "$VAR2"
I'm not sure if it helps a lot, but at least you don't need to declare them again on each parallel step, just load.
There is a feature request to add environment variables to bitbucket-pipelines.yml. If you think this would be a good thing in your case, please add yourself as a watcher and vote on this one.
I hope that helps.
Yeah I have a similar issue. I've separated the build and deployment steps, but the build step is depending on the environment variables since these variables are compiled into the build.
I could have both steps be deployment steps, but that just messes up the Deployments page, since it would include both the build and the actual deployment step. Alternatively I could do as suggested, and make the build step the "deployment" step and pass on the variables as an artifact, but then I can't Redeploy the actual deployment step. The last option is to just merge the two steps together as one, but this just messes up the build script, since I still need the option to run the build step independently on each pull request.
There's basically no good option available, which is unfortunate, because I reckon it wouldn't be too much of a hassle to add something like this:
So the build step would use the deployment environment, without being an actual deployment to that environment.
@Daniel Santos It would be excellent to have the capability that @Nikolaj Dam Larsen mentioned: the "environment" keyword which would have values that match the available deployment environments but would not be a deployment step.
Currently we have to export variables from the deployment step into a shell file that is passed as an artifact to other steps, but as Nikolaj aptly pointed out, that is messy and has limitations (e.g. redeployment basically does nothing). The suggestion of adding the environment keyword is elegant.