Home > Development Tools > git > body text

how to print environment variables in github actions

DDD
Release: 2024-10-10 12:37:19
Original
1018 people have browsed it

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>
Copy after login

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>
Copy after login

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>
Copy after login

This will output the following upon workflow execution:

<code>The GITHUB_WORKSPACE environment variable is: /home/runner/work/my-repo</code>
Copy after login

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!