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

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


1 badge earned


Participate in fun challenges

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


Gift kudos to your peers

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


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!


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
Community Members
Community Events
Community Groups

Using deployment variables in other steps


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.

1 answer

1 accepted

1 vote
Answer accepted

Hi @Neil Nand

I'm not sure if I really got what is your intent with this configuration.

  • Can you share a little bit more on what problem you are trying to solve?
  • How the steps that would consume the deployment variables would be triggered?
  • Why repository variables are not an option for you?

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:

- step:
- echo "I'm building"
- step:
name: Deployment step
deployment: ci-test
- echo "export VAR1=\"$VAR1\"" >> variables
- echo "export VAR2=\"$VAR2\"" >> variables
- variables
- parallel:
- step:
- . variables
- echo "$VAR1"
- step:
- . 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. 

Like Neil_Nand likes this

Thanks for the response @Daniel Santos and sorry it has taken me so long to get back to you your suggestion has worked.

Like Daniel Santos likes this

This workaround seems a little bit messy to me. Is there any good reason why two steps could not share same deployment configuration?

@rafael.moraes as far as I'm aware it's purely because Bitbucket pipelines doesn't support it.

Like Daniel Santos likes this

@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.

Like # people like this

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 =]

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:

name: Build
environment: Staging

name: Deployment
deployment: Staging

So the build step would use the deployment environment, without being an actual deployment to that environment. 

Like Eric Broyles likes this

@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.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events