I see lots of mentions online on how to set environmental variables with ::set-output
but I don't see it mentioned anywhere in official docs anywhere. It's all over the issue trackers with examples though? How does this syntax work?
1 Answer
Antiquated Syntax replaced by writing to $GITHUB_ENV
::set-output
doesn't work anymore. But previously set-output
was "workflow command" to set environmental variables for other steps in the same job. This syntax was removed because writing magic to STDOUT is probably the worst way to set an environmental variable. Anyone could trivially hijack a print statement or debug statement to hijack the CI's STDOUT and change the execution environment.
So GitHub went with the second worst method of doing it: using a file. The new syntax to achieve this is,
echo "{environment_variable_name}={value}" >> "$GITHUB_ENV"
Historic Use
The historic use of ::set-output
looked like this,
run: echo "::set-output name=my_output::my_value"
- name: Set Output
id: step1
run: echo "::set-output name=my_output::my_value"
- name: Use Output
run: echo "${{ steps.step1.outputs.my_output }}"