How do I override high level env variables in a github actions .yml file at lower levels?

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:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># 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
</code>
<code># 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 </code>
# 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.

New contributor

Francis Yang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật