iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
⚙️

How to pass environment variables in GitHub Actions

に公開

I will introduce how to pass environment variables in GitHub Actions.
Although this is intended for use with Node, it can also be applied to other environments.

Tasks on the GitHub Website

  1. Select the Settings tab on your repository page.
  2. Select Secrets and variables.
  3. Select Actions.
  4. Select Variables.
  5. Add environment variables from New repository variables next to Repository variables.

Code

Edit the .yml file within .github/workflows.

- run: npm ci && npm run build
  env:
    GTM_ID: ${{ vars.GTM_ID }}

To use them within a .js file, follow the syntax below.

Node

process.env.GTM_ID

Vite

import.meta.env.VITE_GTM_ID

When using it with Vite, you need to add the VITE_ prefix.

References

Env Variables and Modes | Vite

I have summarized the knowledge gained from developing at home every day for two and a half years! Please take a look if you are interested.

https://doityourself.jp/articles/2026/full-platform-development/

Discussion