Github provides secrets, whose values can be used in workflows. Unfortunately, the values of secrets is protected and we can't easily see it in the repo or debug it in the workflow as it is scrubbed.
Is there a way to define an "environment variable" in the repository that can be easily seen and debugged? My use case is for configuration that can be easily modified if the repo is forked.
2 Answers 2
You can store environment variables in an .env file like this:
FOO=bar
Then you can write code to append data from that file to $GITHUB_ENV:
name: CI
on:
workflow_dispatch:
jobs:
foo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: cat .env >> $GITHUB_ENV
- name: Use the value
run: echo $FOO
You'll need to do cat .env >> $GITHUB_ENV (and use actions/checkout) for each job where you need to access env vars from that file.
DO NOT STORE SECRETS IN .env -- use it only for storing configurations, etc.
Complete code: https://github.com/brc-dd/env-from-file
You can also change .env to something like .env.github to keep things more organized.
1 Comment
FYI: you can pass secret as env variable inside job.
Sample job where I have added foo as a secret in actions workflow:
name: simple secret
id: secret_env
env:
foo: ${{ secrets.foo}}
run: echo $foo
above is example but ignore code syntax issues because of comments format here..
Greetingenvironment variable)