I was trying to use a GitHub Action default environment variable in a workflow today, and was surprised to find that it didn’t work as expected. The workflow contained a step similar to this:

jobs:
  build:
    steps:
        - name: Output job info
          run: echo "Job '${{ env.GITHUB_JOB }}'"

According to the documentation, GITHUB_JOB should contain the job_id of the current job. In this workflow, the job_id should be “build” (as that’s the name of the current job).

But when I ran the workflow all I got was Job ''. I found a couple of posts that seem to hint at the answer.

GitHub sets default environment variables that are available to every step in a workflow run.

In short, the documentation seems to be a little misleading here. The ${{ env.xxxx }} notation works find for env: context variables that you’ve defined yourself, but not for the default environment variables. Either refer to the variable in the way appropriate for the script language (if you’re using run), or if you’re setting a property for an action you can use a different approach. eg.

jobs:
  build:
    steps:
        - name: Output job info
          run: echo "Job '$'"