3

For a repository on GitHub, I have configured an Environment with variables and secrets defined. I'd like to be able to use the entire collection in a GitHub Action without needing to individually map each variable from the github environment to the runner environment.

Given a dev environment defining TOKEN, FOO, BAR, and BAZ and the following workflow:

jobs:
  build:
    runs-on: ubuntu-latest
    environment: dev
    steps:
      - name: Build
        env:
          TOKEN: ${{ secrets.TOKEN }}
          FOO: ${{ vars.FOO }}
          BAR: ${{ vars.BAR }}
          BAZ: ${{ vars.BAZ }}

Is there a clever way to use the settings in the underlying sub-process environment without listing each variable (token, foo, bar, baz) explicitly?

j12y
  • 2,112
  • 3
  • 17
  • 22
  • One possible solution could be to define a single Github environment variable that is the contents of a .env file. So FOO, BAR, and BAZ would all be defined in `env.ENV_FILE_CONTENT` which would be dumped to a file and read by the underlying process. – j12y Mar 06 '23 at 00:31

1 Answers1

0

It seems that such a feature is too difficult for GitHub to implement. How do I get all GitHub secrets into env variables for Actions to access (powershell in my case)?

The answer is, you cannot. The best you can do is export every env variable as a JSON, and then read / parse the whole env variable yourself, which is still bad.

- name: view the secrets context
  shell: bash
  run: echo "$SECRETS_CONTEXT"
  env:
    SECRETS_CONTEXT: ${{ toJson(secrets) }}
vladimirror
  • 729
  • 12
  • 8