How to use env context?

The documentation mentions env context here, but it’s not clear what is it used for? It’s type is string, so it doesn’t look like it makes it possible to access environment variables defined elsewhere in workflow.

What I’m trying to do is define a variable and then use it to define enother variable:

name: Test Pipeline

    types: [opened, synchronize]

  DOCKER_URL: some.docker.url
  DOCKER_IMAGE: ${{env.DOCKER_URL}}/some-namespace/some-image
    - name: Step 1
      run: |
        echo ${DOCKER_IMAGE}

But instead I’m getting an error:

Unrecognized named-value: 'env'. Located at position 1 within expression: env.DOCKER_URL

Even when usin env alone as in SOME_ENV: ${{env}} it still gives similar error - looks like this context is never set up?

Is it even possible to achieve that?


You cannot use env context in the value of a workflow environment variable. But you can use it in jobs.<job_id>.steps.env.

Please see the example yml:

env usage.png


Seems this is not the way to get the contents of an environment variable. There is another post which shows the syntax to retrieve an environment variable, at least, one of the predefined ones.

1 Like

The link you posted doesn’t actualy mention that env context cannot be used in job variables.

But I have tried to create simple workflows and it looks like it is only possible to use env inside a step:

Wonder if that is expected?

1 Like

Wow, you’re right, @inikolaev, the Workflow Spec is misleading here. No mention that top level env values must be used in steps.

I need to use them in matrix strategies and other places, so this isn’t very useful. I wish the preprocessor would properly handle these (e.g. in ${{ env.NAME }} locations). It feels like either a bug in the spec or the preprocessor implementation.

Misleading documentation, this pretty basic feature is not available.