Configuring GitLab CI for a React app with environment variables
I'm trying to configure I'm updating my dependencies and Setting up a CI/CD pipeline for a React application using GitLab CI has been quite the adventure. Currently, I’m trying to ensure that my environment variables are correctly configured for different stages of the deployment. In my `.gitlab-ci.yml` file, I have defined the stages and jobs, but the environment variables seem to be inaccessible during the build phase. Here’s a snippet of my configuration for clarity: ```yaml stages: - build - test - deploy variables: NODE_ENV: 'production' REACT_APP_API_URL: 'https://api.example.com' build: stage: build script: - npm install - npm run build - echo $REACT_APP_API_URL ``` Despite having them declared, when I run the pipeline, the echo command returns an empty string. I’ve tried a few things to troubleshoot this. First, I made sure that the environment variables are set in the GitLab project settings under CI/CD -> Variables, verifying that their scope is correct. I also attempted to use the `env` command in my script just to see if it’s an issue with how I’m referencing the variables, but they still didn’t show up. I’ve checked GitLab's documentation, and it seems that variables should be available in the job’s environment. Lastly, I experimented with different syntax for referencing the variables, such as `printenv` to capture all environment variables, but nothing worked. Is there a specific reason the environment variables might not be available during the build phase, or is there a step I might be missing in my CI configuration? Any insights or best practices for handling environment variables in GitLab CI for a React project would be greatly appreciated. What are your experiences with this? I'm coming from a different tech stack and learning Yaml. Am I missing something obvious?