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

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

Avatar

1 badge earned

Collect

Participate in fun challenges

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

Challenges
Coins

Gift kudos to your peers

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

Recognition
Ribbon

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!

Leaderboard

Bitbucket pipelines not getting env variables in React

I'm using Bitbucket pipelines to deploy my react app to the s3 bucket, deployments work fine but unfortunately, my `process.env ` variables are undefined. I already add my all env variables in deployment variables.

bitbucket-pipeline.yml

image: node:14

pipelines:
  branches:
    master:
      - parallel:
        - step:
            name: Build and Test
            caches:
              - node
            script:
              - rm -rf package-lock.json
              - npm install
              - npm rebuild node-sass
              - CI=false npm run build:prod
            artifacts:
              - build/**
        - step:
            name: Security Scan
            script:
              # See more security tools at https://bitbucket.org/product/features/pipelines/integrations?&category=security
              - pipe: atlassian/git-secrets-scan:0.5.1
      - step:
          name: Deploy to Production
          deployment: Production
          trigger: manual
          clone:
            enabled: false
          script:
            # sync your files to S3
            - pipe: atlassian/aws-s3-deploy:1.1.0
              variables:
                AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
                AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
                AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
                S3_BUCKET: $S3_BUCKET
                LOCAL_PATH: 'build'

 

1 answer

1 vote
Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Mar 08, 2022

Hi @Zain Khan

Welcome to the community.

Based on my understanding, you've added your environment variables in the "production" Deployment variables.
However, after it was deployed to the S3 bucket, the process.env file variables are undefined.

If this is correct, I can see that you've built your application in the first step which is "Build and Test" with no deployment environment.
Then you only use deployment in the third step which is "Deploy to Production".
I believe variables are undefined in the file process.env because your environment variables are only available in the "Deploy to Production" step and that is where you only used the "deployment: Production" configuration.

For this, the best I can suggest is for you to use repository variables instead so that your environment variables are accessible to all your steps.

Hope it helps and let me know how it goes.

Regards,
Mark C

Leonardo Lima
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!
Aug 25, 2023

But that doesn't solve the problem.
we need to access a specific Env variable in the build step.
how can we build an image pointing to production and staging using only repository variables?

Mark C
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
Aug 28, 2023

Hi @Leonardo Lima

I'm just wondering, where does process.env is currently defined?
Is it defined when you run the step "Build and Test" or using Bitbucket Cloud Pipelines environment variables (e.g. deployments or repository variables)?

Regards,
Mark C

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events