Syntax to refer to env var in container.image

I can’t figure out the syntax to refer to an environment variable in jobs.<job_id>.container.image

This works OK:

name: test

on:
  push:

jobs:
  job1:
    container:
      image: eu.gcr.io/path/to/image:tag
    steps:
      - name: "Build:checkout"
        uses: actions/checkout@v2
      - run: |
          echo "hello world"
        id: do

(I’ve left out the specifics of what the job is going but the point here is that this is running on a container image)

However if I do this:

name: test

env:
  IMAGE: eu.gcr.io/path/to/image:tag

on:
  push:

jobs:
  job1:
    container:
      image: env.IMAGE
    steps:
      - name: "Build:checkout"
        uses: actions/checkout@v2
      - run: |
          echo "hello world"
        id: do

It fails with:

Starting job container
/usr/bin/docker pull env.IMAGE
invalid reference format: repository name must be lowercase

I’ve tried various other ways to get it to refer to the image name stored in my env var

image: ${env.IMAGE}
image: ${{env.IMAGE}}

but I can’t figure out the syntax. Help!!

There is unfortunately no syntax that works, the env context is not available there. Relevant quote from the contexts documentation:

You can use the env context in the value of any key in a step except for the id and uses keys.

1 Like

Yes, very disappointing, thanks for the answer.

1 Like