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'
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.