Context
On https://docs.github.com/en/actions/learn-github-actions/environment-variables they describe a way to add an environment variable with yaml:
jobs:
job_name:
env:
NAME: value
On https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions/#setting-an-environment-variable linked from the same place, shows how to add an environment variable from script steps:
echo "NAME=value" >> $GITHUB_ENV
Question
I'm looking for a way to do the opposite: given that an env var was added with one of the above options, fully remove it so that subsequent job steps don't see it either.
I tried
echo "NAME=" >> $GITHUB_ENV
but it just sets it to empty string, I need it gone so that env
doesn't list it any more.
Resources
Raised it GitHub community too: https://github.community/t/remove-environment-variable-from-job/214815 (dead link, not sure where GitHub migrated these...)
NAME
. A somewhat brute force way to do this would be to save a copy ofGITHUB_ENV
prior to addingNAME
and then overwrite the new one with the copy once you are done usingNAME
. – NoctambulousGITHUB_ENV
points to a file, are you suggesting I couldsed
the variable out of it? Note: the variable was not set by me, it was set by one of theuses
steps. – Deutsch$GITHUB_ENV
is changing between every step. It only records the delta to be propagated toenv.
, does not contain existing variables. – Deutschenv: NAME: ${{ steps.<step_id>.outputs.<output_name> }}
, (or in other jobs) instead of adding it to the$GITHUB_ENV
. Wouldn't it be an option? – Ackleyif
on a previous step that created it) to make sure it's not created. – Deutsch