I'm facing an issue with my Cloud Build configuration YAML file, which is not working as expected. I have a multi-step build process, and I'm encountering problems with environment variable handling and build submission. Below is my YAML configuration, and I'd appreciate any insights or suggestions on how to troubleshoot and fix the issue:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
echo "REACT_APP_BACKEND_BASE_URL=/" > .env
echo "REACT_APP_FIREBASE_API_KEY=${_REACT_APP_FIREBASE_API_KEY}" >> .env
echo "REACT_APP_FIREBASE_AUTH_DOMAIN=${_REACT_APP_FIREBASE_AUTH_DOMAIN}" >> .env
echo "REACT_APP_FIREBASE_DATABASE_URL=${_REACT_APP_FIREBASE_DATABASE_URL}" >> .env
echo "REACT_APP_FIREBASE_PROJECT_ID=${_REACT_APP_FIREBASE_PROJECT_ID}" >> .env
echo "REACT_APP_FIREBASE_STORAGE_BUCKET=${_REACT_APP_FIREBASE_STORAGE_BUCKET}" >> .env
echo "REACT_APP_FIREBASE_MESSAGING_SENDERID=${_REACT_APP_FIREBASE_MESSAGING_SENDERID}" >> .env
cat .env
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
export $(grep -v '^#' .env | xargs -d '\n')
npx env-cmd -f .env npm run build
gcloud builds submit --tag gcr.io/$PROJECT_ID/test:test
options:
logging: CLOUD_LOGGING_ONLY
_REACT_APP_FIREBASE_MESSAGING_SENDERID - these values are coming from cloud secret.
After running a Cloud Build process, I've noticed that the environment variables defined in my .env file are not being set correctly within my application. I've verified that the .env file is correctly created during the build process, but the values seem to be missing when the application runs
I'd appreciate any insights or suggestions on how to ensure that the environment variables from the .env file are properly set in my application after the Cloud Build process. Thank you for your assistance!