I’m trying to set up environment variables in a GitHub Actions workflow for my React Native Android build (./gradlew bundleRelease
). Despite setting the environment variables either through the env
section or using export
commands, the build is not recognizing some of the variables. Specifically, I keep getting errors stating that certain environment variables are missing during the build process.
Here are the methods I’ve tried:
-
Setting the environment variables directly using GitHub Actions’
env
syntax:- name: Set environment variables env: MAIN_URL: ${{ vars.MAIN_URL }} ORIGIN: ${{ vars.ORIGIN }} ENV: ${{ vars.ENV }} AWS_REGION: ${{ secrets.AWS_REGION }} AWS_USER_POOL_ID: ${{ secrets.AWS_USER_POOL_ID }} AWS_APP_CLIENT_WEB_ID: ${{ secrets.AWS_APP_CLIENT_WEB_ID }} AWS_IDENTITY_POOL_ID: ${{ secrets.AWS_IDENTITY_POOL_ID }} AWS_EXTERNAL_USER_POOLS_ID: ${{ secrets.AWS_EXTERNAL_USER_POOLS_ID }} AWS_EXTERNAL_USER_POOLS_WEB_CLIENT_ID: ${{ secrets.AWS_EXTERNAL_USER_POOLS_WEB_CLIENT_ID }} ENABLE_SENTRY: ${{ secrets.ENABLE_SENTRY }}
-
Exporting the environment variables using
export
:- name: Export environment variables run: | export MAIN_URL=$MAIN_URL export ORIGIN=$ORIGIN export ENV=$ENV export AWS_REGION=$AWS_REGION export AWS_USER_POOL_ID=$AWS_USER_POOL_ID export AWS_APP_CLIENT_WEB_ID=$AWS_APP_CLIENT_WEB_ID export AWS_IDENTITY_POOL_ID=$AWS_IDENTITY_POOL_ID export AWS_EXTERNAL_USER_POOLS_ID=$AWS_EXTERNAL_USER_POOLS_ID export AWS_EXTERNAL_USER_POOLS_WEB_CLIENT_ID=$AWS_EXTERNAL_USER_POOLS_WEB_CLIENT_ID export ENABLE_SENTRY=$ENABLE_SENTRY
Configure project :app
Reading env from: .env
*** Missing .env file ****
However, the build command (./gradlew bundleRelease
) does not seem to recognize the variables and throws errors about missing values. What am I doing wrong?
Janith Gamage is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.