Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set dynamic environment variable for each step and use in code

Kashish Solanki
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 7, 2021

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
Eddie Webbinaro
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 9, 2021

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.


https://support.atlassian.com/bitbucket-cloud/docs/set-up-and-monitor-deployments/

 

 

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events