Answers: <h1>Antiquated Syntax replaced by writing to <a href="https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable" rel="nofollow noreferrer"><code>$GITHUB_ENV</code></a></h1>
  <p><code>::set-output</code> doesn't work anymore. But previously <code>set-output</code> was <a href="https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#about-workflow-commands" rel="nofollow noreferrer">&quot;workflow command&quot;</a> to set environmental variables <strong>for other steps in the same job</strong>. This syntax was removed because writing magic to STDOUT is probably the <em>worst</em> 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.</p>
  <p>So GitHub went with the second worst method of doing it: <a href="https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable" rel="nofollow noreferrer">using a file.</a> The new syntax to achieve this is,</p>
  <pre class="lang-shell prettyprint-override"><code>echo &quot;{environment_variable_name}={value}&quot; &gt;&gt; &quot;$GITHUB_ENV&quot;
  </code></pre>
  <h1>Historic Use</h1>
  <p>The historic use of <code>::set-output</code> looked like this,</p>
  <p>run: echo &quot;::set-output name=my_output::my_value&quot;</p>
  <pre class="lang-yaml prettyprint-override"><code>- name: Set Output 
    id: step1 
    run: echo &quot;::set-output name=my_output::my_value&quot; 
  - name: Use Output 
    run: echo &quot;${{ steps.step1.outputs.my_output }}&quot; 
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2024-11-15T08:40:01.757Z
Answers: 2024-11-15T08:46:18.333Z
Answers: 2024-11-15T08:46:18.333Z
Answers: Evan Carroll
Body: <p>I see lots of mentions online on how to set environmental variables with <code>::set-output</code> 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?</p>
  
Tags: <github-actions>
Title: What is GitHub Actions ::set-output syntax and how does it work?
UserDisplayName: Evan Carroll
ThreadText: # What is GitHub Actions ::set-output syntax and how does it work?
  
  (Asked by: username_0 on 2024-11-15)
  
  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?
  
  **Tags:** github-actions
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2024-11-15. Score: 0
  
  # Antiquated Syntax replaced by writing to [`$GITHUB_ENV`](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable)
  
  `::set-output` doesn't work anymore. But previously `set-output` was ["workflow command"](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#about-workflow-commands) 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.](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable) The new syntax to achieve this is,
  
  ```shell
  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"
  
  ```yaml
  - name: Set Output 
    id: step1 
    run: echo "::set-output name=my_output::my_value" 
  - name: Use Output 
    run: echo "${{ steps.step1.outputs.my_output }}" 
  
  ```
  
  
  ---
  
  