Home  >  Article  >  Development Tools  >  how to print environment variables in github actions

how to print environment variables in github actions

DDD
DDDOriginal
2024-10-10 12:37:19993browse

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

how to print environment variables in github actions

How can I print environment variables in GitHub Actions YAML workflows?

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>

Is there a command or function to display environment variables in GitHub Actions?

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.

How to use the 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn