Reputation: 46460
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
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.
Raised it GitHub community too: https://github.community/t/remove-environment-variable-from-job/214815 (dead link, not sure where GitHub migrated these...)
Upvotes: 15
Views: 5606
Reputation: 170310
As of today, this is not possible, see https://github.com/actions/runner/issues/1126 ticket that tracks this feature request.
You will have to rely on your own build scripts to add logic for unsetting these variables that might be defined before they are called.
Upvotes: 1