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
- Select the Settings tab on your repository page.
- Select
Secrets and variables. - Select
Actions. - Select
Variables. - Add environment variables from
New repository variablesnext toRepository 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.
Discussion