Search code examples
githubgithub-actions

How do I specify a container image in GitHub actions using a secret?


Setting the "container" image below is not allowed, but I would rather not hard code it.

  build-web:

    needs: login-ecr
    runs-on: ubuntu-latest

    env:
      AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}

    container:
      image: ${{ secrets.AWS_ECR_REPOSITORY }}

Github's container documentation does not speak to it, that I can tell.


Solution

  • This is covered under Context availability:

    Workflow key Context Special functions
    jobs.<job_id>.container.image github, needs, strategy, matrix, vars, inputs None

    So, if you don't want to hardcode, you could use the vars context, or pass in a secret from another job via needs.