This guide explains how to set output variables in GitHub Actions using the set-output action. It covers setting a single output variable, multiple output variables in a single action, and accessing output variables set by other jobs.
How do I set output variables in GitHub Actions?
You can set output variables in GitHub Actions using the set-output
action. This action allows you to set a single output variable at a time. The syntax for the set-output
action is as follows:
<code class="yaml">- set-output: name: name-of-output-variable value: value-of-output-variable</code>
For example, the following action will set an output variable called my-output-variable
with the value my-output-value
:
<code class="yaml">- set-output: name: my-output-variable value: my-output-value</code>
Can I set multiple output variables in a single GitHub Action?
Yes, you can set multiple output variables in a single GitHub Action by using multiple set-output
actions. For example, the following action will set two output variables: my-output-variable1
with the value my-output-value1
and my-output-variable2
with the value my-output-value2
:
<code class="yaml">- set-output: name: my-output-variable1 value: my-output-value1 - set-output: name: my-output-variable2 value: my-output-value2</code>
How do I access output variables set by other jobs in GitHub Actions?
You can access output variables set by other jobs in GitHub Actions by using the jobs.<job_name>.outputs.<output_variable_name>
syntax. For example, the following action will access the my-output-variable
output variable set by the my-job
job:
<code class="yaml">- echo: ${{ jobs.my-job.outputs.my-output-variable }}</code>
The above is the detailed content of how to set output in github actions. For more information, please follow other related articles on the PHP Chinese website!