As described in other answers the use of $GITHUB_ENV is limited to steps within a single job.
If you want to use a variable across multiple jobs there is a solution, but it's not concise.
The steps are:
- Define a job that does that actual commands, and saves the result as an
output of a step, and that value as an output of the job.
- In each job where you need the value, reference the commands job outputs.
Here is an example job to save the output.
jobs:
command-outputs:
runs-on: ubuntu-latest
outputs:
GITHUB_SHA_SHORT: ${{ steps.commands.outputs.GITHUB_SHA_SHORT }}
steps:
- id: commands
run: |
echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-6)" >> "$GITHUB_OUTPUT"
Then use that value in another job:
different-job:
needs: [command-outputs]
env:
GITHUB_SHA_SHORT: ${{ needs.command-outputs.outputs.GITHUB_SHA_SHORT }}
steps:
- name: Tag image
run: git tag v1.2.3 ${{ env.GITHUB_SHA_SHORT }} -m "Tagged"
# do other things
If you only need the value in one step you can skip the setting of env and use the needs directly.
set-envwould work in a previous step. help.github.com/en/articles/…git rev-parse --short $GITHUB_SHAovercutto create a short version of the rev, because it automatically uses the shortest length which doesn't yield collisions. So while a length of 6 may work fine in the beginning, that may not apply anymore when the number of objects in the repository grows.