As far as I know, there are two ways to set environment variables in Github Actions:
Repository secrets page
But what if I don't want them to be secret? On the picture above, SERVER_PREFIX and ANALYTICS_ENABLED shouldn't be secret. Is there a way to set up env variables on the settings page and make them visible? In Travis we had that option.
To add variables to the repository, you can define the variable in Secrets tab and use them in the yaml file. Note: You can access the variable in the build. xml as highlighted below. And, to make use of your variables as unencrypted, you can directly use them in the yml as highlighted below.
4. Fill in the form appropriately ( Name and Value) and click the Add secret button to submit. Now the API_KEY is saved in GitHub Secrets. In this form, GitHub securely sets environment variables as secrets that you can reference when working on GitHub Actions.
Instead of hard-coding, you may want to store your environment variable securely, and GitHub secrets can do just that. GitHub Actions environment variables encrypts the values you put in secrets, so they are not visible nor readable in the naked eye.
The env keyword is a dedicated property defined by the GitHub Actions to declare our variables. Better to use this one, if you know all the values of each variable at the beginning of the script. Define an environment variable across the entire job
First, push your code to GitHub as you did in the previous sections. 2. Next, navigate to your project on GitHub and click on the Settings tab. Click on Secrets in the tab below to start adding a secret. 3. Next, click on the New repository secret, and you’ll see a form to fill in details about the secret you’re adding. 4.
There isn't an option to add non-secret ENV variables on GitHub page at now.
You can create workflow-scope ENV variables in workflow step.
env:
SERVER_PREFIX: SOME_PREFIX
Then access by:
${{ env.SERVER_PREFIX }}
If you don't need to use them in the Action's YAML, just define your variables in a downloadable file and then use something like curl or wget to get them into your build environment.
For instance, I've done something similar for common CI files and now I've multiple projects running the same project building scripts, their local action is simply like: download an .sh file, run it.
If you need to set up variables in one of your build steps, to be used later by some other action, have a look at this (but I've never tried it myself).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With