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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Set dynamic environment variable for each step and use in code

Here are things I want to do with Bitbucket pipelines:


  • I had written a bitbucket pipeline to deploy multiple environments for one of my react app, in which the first environment/stage deployment will be auto, else I have to do it manually. But the build for code will be generated only once for the first step, for the rest of all steps, it should have to use the same old generated build.
  • Now, each environment has different config variables such as API URLs or other creds. And as I mentioned that build will generate only once, so identification env variable, I can set only once before build generate
    • Suppose: REACT_APP_ENV=dev npm run build

This is my scenario, now my question is that how can we set the env variable dynamically on each step without creating a new build?

Or is there any way to set the env variable in the Bitbucket site and access in code dynamically so I can manage through that.


Else create a new build for each environment is the last option for me.

1 answer

0 votes

I would suggest using deployment environment variables, which are intended for just this.

Deployment variables override both team and repository variables. Also variables with the same name can have different values for each deployment environment. For example, you could set a different $DEPLOYMENT_SECRET_KEY for each environment.



 - step:
image: cibuilds/hugo
name: Build Site
- echo $SOME_TOKEN # repo value for testing, etc
- step:
image: cibuilds/hugo
name: Staging Deployment
deployment: Staging
- echo $SOME_TOKEN # statging specific value
- step:
image: cibuilds/hugo
name: Switch to Live Deployment
deployment: Production
trigger: manual
- echo $SOME_TOKEN # different value

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bitbucket

New improvements to user management in Bitbucket Cloud 👥

Hey Community! We’re willing to wager that quite a few of you not only use Bitbucket, but administer it too. Our team is excited to share that we’ll be releasing improvements throughout this month of...

3,749 views 10 16
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you