I have a .yml file for my CI/CD pipeline in Github Actions. I have an env variable that gets set at the job level, and then reset at the step level for a single step. However, the env at the step level doesn’t get registered.
The following is the entire yml file:
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build, Lint and Test
on:
push:
branches:
- dev
- main
pull_request:
branches:
- dev
- main
- CU-*
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_lint_test:
runs-on: ubuntu-latest
timeout-minutes: 20
environment: staging
env:
CI: true
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
NEXT_PUBLIC_MAPBOX_PUBLIC_TOKEN: ${{ secrets.NEXT_PUBLIC_MAPBOX_PUBLIC_TOKEN }}
ALLOWED_IMAGE_DOMAINS: ${{ vars.ALLOWED_IMAGE_DOMAINS }}
NEXT_PUBLIC_SERVER_DOMAIN: ${{ vars.NEXT_PUBLIC_SERVER_DOMAIN }}
NEXT_PUBLIC_API_TIMEOUT: ${{ vars.NEXT_PUBLIC_API_TIMEOUT }}
NEXT_PUBLIC_API_RETRY_COUNT: ${{ vars.NEXT_PUBLIC_API_RETRY_COUNT }}
NEXT_PUBLIC_SITE_URL: ${{ vars.NEXT_PUBLIC_SITE_URL }}
NEXT_PUBLIC_AUTH0_DOMAIN: ${{ vars.NEXT_PUBLIC_AUTH0_DOMAIN }}
NEXT_PUBLIC_AUTH0_CLIENT_ID: ${{ vars.NEXT_PUBLIC_AUTH0_CLIENT_ID }}
NEXT_PUBLIC_SENTRY_DSN: ${{ vars.NEXT_PUBLIC_SENTRY_DSN }}
NEXT_PUBLIC_HEAP_ID: ${{ vars.NEXT_PUBLIC_HEAP_ID }}
NEXT_PUBLIC_APP_ENV: ${{ vars.NEXT_PUBLIC_APP_ENV }} // ENV VARIABLE HERE
NEXT_PUBLIC_STAGING_URL: ${{ vars.NEXT_PUBLIC_STAGING_URL }}
NEXT_PUBLIC_PRODUCTION_URL: ${{ vars.NEXT_PUBLIC_PRODUCTION_URL }}
NEXT_PUBLIC_DEVELOPMENT_URL: ${{ vars.NEXT_PUBLIC_DEVELOPMENT_URL }}
NEXT_PUBLIC_GOOGLE_MAPS_API_KEY: ${{ secrets.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY }}
CYPRESS_TEST_LOGIN_EMAIL: ${{ secrets.TEST_LOGIN_EMAIL }}
CYPRESS_TEST_LOGIN_PASSWORD: ${{ secrets.TEST_LOGIN_PASSWORD }}
steps:
- uses: actions/checkout@v4
with:
clean: true
- uses: actions/checkout@v4
with:
repository: 'akadenia/PerimeterTypes'
path: PerimeterTypes
token: ${{ secrets.CI_TOKEN }}
clean: true
- name: Git Submodule Update
run: |
git submodule update --init --recursive
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- run: npm ci
- name: Run Linter
run: npm run lint
- name: Build code
run: npm run build
- name: Echo Environment Variable
run: echo $NEXT_PUBLIC_APP_ENV
env:
NEXT_PUBLIC_APP_ENV: test
- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: npm start
env: NEXT_PUBLIC_APP_ENV=test // ENV HERE AGAIN
The env variable in question is NEXT_PUBLIC_APP_ENV. It gets set at the job level to be ‘staging’ with:
${{ vars.NEXT_PUBLIC_APP_ENV }}
However, it’s reset at the step level for the Cypress run step, which uses:
env:
NEXT_PUBLIC_APP_ENV: test
However, within cypress testing, the APP_ENV variable gets registered as staging instead of test like it’s supposed to. Is there a reason for this? The previous echo correctly logs APP_ENV as being test, and the docs for the github action say to use that separate syntax for env variables in the Cypress run step. I’ve also tried using start: npm run dev instead of start: npm start which works since I directly set the env variable in my dev script, but this causes cypress testing to take almost twice as long. Setting the env variable in my start script doesn’t have any effect.
Francis Yang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.