how to print environment variables in github actions

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!

原文来自:www.php.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容