0

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 1

0

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 }}" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.