Support saving environment variables between steps #26407
-
With https://github.community/t5/GitHub-Actions/YAML-folded-multiline-strings-interpreted-as-multiple-commands/m-p/30876#M593 solved, the only thing standing in the way of reusing a lot of commands between Linux/MacOS and Windows when building C++ with CMake is an option to keep environment variables between steps (currently the environment is reset after each step). For example, an option I’ve seen that it’s possible to set global environment variables with |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 1 reply
-
Using set-env I was able to achieve the desired result. On Windows, VS related environment variables are set by a third-party batch script, so I had to add them with set-env manually after calling the batch script. Instead of filtering the relevant environment variables, I just make every environment variable global using set-env. The script can be found here. |
Beta Was this translation helpful? Give feedback.
-
Thanks for creating that script. I would be a little careful with that script as you are stomping on PATH rather an updating it with append-path. In most cases it probably won’t be an issue but you never know. |
Beta Was this translation helpful? Give feedback.
-
I’ve been going round in cycles with this as I had my set-env like ::set-env VERSION=0.0.21-preview Which looks like it’s working but it needs to be ::set-env name=VERSION::0.0.21-preview |
Beta Was this translation helpful? Give feedback.
-
Link has moved to: |
Beta Was this translation helpful? Give feedback.
-
How do I actually use these variables? I’m setting a variable like this in a script:
And trying to use it in my workflow:
But before my action runs I get this error:
I have tried initialising it at both the job and workflow level like below but I still get the same error:
|
Beta Was this translation helpful? Give feedback.
-
The
When inside a |
Beta Was this translation helpful? Give feedback.
-
This is being deprecated due to a vulnerability - see https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/ Now use:
|
Beta Was this translation helpful? Give feedback.
-
This method was deprecated due to a security vulnerability please see Support saving environment variables between steps for the new method. |
Beta Was this translation helpful? Give feedback.
-
It’s also possible to use job-scoped environment variables, no? See this link: https://kevsoft.net/2020/04/25/creating-a-job-scoped-computed-environment-variable-in-github-actions.html for example:
|
Beta Was this translation helpful? Give feedback.
-
Yes, but if you need to set an environment variable dynamically in a step, then you need to use environment files. |
Beta Was this translation helpful? Give feedback.
This is being deprecated due to a vulnerability - see https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Now use: