How to pass secrets as environment variables into a Docker Github Action?

  docker, dockerfile, github, github-actions

In my workflow I’m running a custom action using the following step:

- name: Run action
  uses: ./backend
  env:
    MY_SECRET: ${{ secrets.MY_SECRET }}

And here’s action.yml:

name: "Backend"
on: [pull_request]
runs:
  using: 'docker'
  image: "Dockerfile"

For some reason, MY_SECRET is empty in my Dockerfile. I tried accessing it both in a shell script file and the RUN command:

RUN echo "MY_SECRET: $MY_SECRET"

But it’s always empty.

I tried both repository-level and organization-level secrets, but the environment variable is always empty.

Any idea why?

Source: Docker Questions

LEAVE A COMMENT