This article describes how to print environment variables within GitHub Actions YAML workflows. The echo command is primarily utilized, followed by the $$ syntax. The env variable can also be leveraged in more intricate scenarios, along with other Gi
To print environment variables in GitHub Actions YAML workflows, you can use the echo
command followed by the $$
syntax. For example:
<code class="yaml">- name: Print environment variables run: | echo "## Environment Variables" echo "-------------------------" echo "HOME: $$HOME" echo "PATH: $$PATH" echo "GITHUB_WORKSPACE: $$GITHUB_WORKSPACE"</code>
This will output the following upon workflow execution:
<code>## Environment Variables ------------------------- HOME: /home/runner PATH: /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/hostedtoolcache/Node.js/tools/node/16.13.0/bin GITHUB_WORKSPACE: /home/runner/work/my-repo</code>
The echo
command is the most common way to display environment variables in GitHub Actions. For more complex scenarios, you may also use the env
variable and other functions provided by the GitHub Actions toolkit.
env
variable to print environment variables in GitHub Actions?The env
variable in GitHub Actions represents the current environment of the workflow run. You can access individual environment variables using the env.VARIABLE_NAME
syntax. For example:
<code class="yaml">- name: Print the GITHUB_WORKSPACE environment variable run: | echo "The GITHUB_WORKSPACE environment variable is: $${{ env.GITHUB_WORKSPACE }}"</code>
This will output the following upon workflow execution:
<code>The GITHUB_WORKSPACE environment variable is: /home/runner/work/my-repo</code>
The above is the detailed content of how to print environment variables in github actions. For more information, please follow other related articles on the PHP Chinese website!