Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to set non-secret environment variables in Github Actions on the Settings page?

As far as I know, there are two ways to set environment variables in Github Actions:

  • Hardcoding them into YAML file
  • Adding them as repository secrets on the settings page

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.

like image 717
lencse Avatar asked Dec 15 '20 22:12

lencse


People also ask

How do I declare variables in GitHub Actions?

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.

How to add environment variables to GitHub secrets?

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.

What are GitHub secrets and how do they work?

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.

What is the use of env keyword in GitHub actions?

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

How to add a repository secret on GitHub?

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.


Video Answer


2 Answers

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 }}

like image 178
Milan Dufek Avatar answered Nov 15 '22 07:11

Milan Dufek


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).

like image 39
zakmck Avatar answered Nov 15 '22 05:11

zakmck