Hello,
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?
Tl;Dr
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.
export DATABASE_HOST=$TEST_DATABASE_HOST
* 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
pipelines:
default:
- step:
script:
- echo "I'm building"
- step:
name: Deployment step
deployment: ci-test
script:
- echo "export VAR1=\"$VAR1\"" >> variables
- echo "export VAR2=\"$VAR2\"" >> variables
artifacts:
- variables
- parallel:
- step:
script:
- . variables
- echo "$VAR1"
- step:
script:
- . 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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the response @Daniel Santos and sorry it has taken me so long to get back to you your suggestion has worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This workaround seems a little bit messy to me. Is there any good reason why two steps could not share same deployment configuration?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@rafael.moraes as far as I'm aware it's purely because Bitbucket pipelines doesn't support it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Neil Nand thanks, would be great as a new feature and it doesn't seems too complex to implement that. Makes sense to reuse variables in multiple steps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @rafael.moraes,
yes, it would be great if we have this feature.
We have a feature request that should cover this need. The one shared in my comment above.
Thank you @Neil Nand for helping here =]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
step:
name: Build
environment: Staging
step:
name: Deployment
deployment: Staging
So the build step would use the deployment environment, without being an actual deployment to that environment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.