1

I cannot figure out how to populate a Github Action job environment variable via bash command.

I have tried this:

    - name: Environment Variables
      run: |
        echo ::set-env name=DJANGO_SECRET_KEY::"${{ secrets.DJANGO_SECRET_KEY }}"

and this:

    - name: Environment Variables
      run: |
        echo ::set-env name=DJANGO_SECRET_KEY::${{ secrets.DJANGO_SECRET_KEY }}

however neither seem to work.

I don't want to do it the normal way:

 - name: Environment Variables
      env:
        DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }}

as these env variables don't seem to persist between different steps in the job. Is there a way to do this?

COB
  • 236
  • 1
  • 14

1 Answers1

1

You can try this:

- name: Set env-var
  run: |
    echo "::set-env name=MY_ENV_VAR::test"

- name: Get env-var
  run: |
    echo ${{ env.MY_ENV_VAR }}

or simply use an out-of-the-box action:

- name: set environment variables
  uses: allenevans/set-env@v1.0.0
  with:
    MY_ENV_VAR: 'my value'

- name: Printenv
  run: |
    echo "MY_ENV_VAR=${MY_ENV_VAR}"
    printenv
Tomasz Bartkowiak
  • 12,154
  • 4
  • 57
  • 62
  • Thanks Tomasz. Any idea why setting it using `env:` doesn't seem to allow it persist across steps? – COB Apr 09 '20 at 06:20