Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass default env variables set by github to the docker #19

Closed
shreyaspurohit opened this issue Jun 3, 2021 · 5 comments
Closed

Pass default env variables set by github to the docker #19

shreyaspurohit opened this issue Jun 3, 2021 · 5 comments

Comments

@shreyaspurohit
Copy link

I would like to use the default env vars set by the Github Actions as defined here - https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables - in the docker. Right now, these are not being set. It can be verified by executing printenv in the shell.

@pangteypiyush
Copy link

Environment variables are passed down to the action container, which you can verify from the job logs:

/usr/bin/docker run <REDACTED> -e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA -e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID -e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF

This docker container action creates your container using: https://github.com/addnab/docker-run-action/blob/main/entrypoint.sh#L11
So, in order to pass these env variables further, you have to explicitly define them in options:

      - uses: addnab/docker-run-action@v3
        with:
          image: alpine:latest
          options: -v ${{ github.workspace }}:/home -e FOO -e GITHUB_REF
          run: |
            echo foo $FOO
            echo REF $GITHUB_REF
        env:
          FOO: BAR

@shreyaspurohit
Copy link
Author

Got it, thanks

@orihomie
Copy link

orihomie commented Jul 2, 2021

@pangteypiyush hi, have u tried your method with gh actions variables? I mean to pass needs.job.output.somevar to this action as an environment variable?

@pangteypiyush
Copy link

@orihomie this?

      - uses: addnab/docker-run-action@v3
        env:
          SOMEVAR: ${{ needs.job.outputs.somevar }}
        with:
          image: alpine:latest
          options: -e SOMEVAR
          run: |
            echo $SOMEVAR

@orihomie
Copy link

orihomie commented Jul 2, 2021

Yes, I offer to move to #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants