如何在GitHub Actions表达式语法中引用上下文值? [英] How to reference context values in GitHub Actions expression syntax?

查看:103
本文介绍了如何在GitHub Actions表达式语法中引用上下文值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在GitHub Action的 env:部分中设置环境变量,并使用

I want to set an environment variable in the env: section of a GitHub Action and make use of the Contexts and expression syntax for GitHub Actions. I tried this:

jobs:
  build:
    runs-on: ubuntu-latest

    env:
      MYVAR: ${{ format('{0}:{1}', ${{ env.PATH }}, ${{ env.HOME }} ) }}

    steps:
    - name: Check environment
      run: echo $MYVAR

这将导致错误消息:

### ERRORED 10:45:52Z

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unexpected symbol: '${{'. Located at position 19 within expression: format('{0}:{1}', ${{ env.PATH

此语法:

    env:
      MYVAR: ${{ format('{0}:{1}', {{ env.PATH }}, {{ env.HOME }} ) }}

导致错误:

### ERRORED 13:14:18Z

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unexpected symbol: '{{'. Located at position 19 within expression: format('{0}:{1}', {{ env.PATH

和:

    env:
      MYVAR: ${{ format('{0}:{1}', env.PATH, env.HOME ) }}

导致错误:

### ERRORED 13:16:12Z

- Your workflow file was invalid: The pipeline is not valid. .github/workflows/main.yml (Line: 10, Col: 14): Unrecognized named-value: 'env'. Located at position 19 within expression: format('{0}:{1}', env.PATH, env.HOME )

我知道用于设置环境变量,但是我想了解表达式的语法./p>

I'm aware of the solutions in How do i set an env var with a bash expression in GitHub Actions? and Github Actions, how to share a calculated value between job steps? for setting environment variables, but I would like to understand the expression syntax.

推荐答案

正如@jonrsharpe所指出的,在工作流环境变量的值中不能使用 env 上下文.在这里进行了讨论:

As @jonrsharpe pointed out, it is not possible to use the env context in the value of a workflow environment variable. This was discussed here:

https://github.community/t5/GitHub-Actions/How-to-use-env-context/td-p/38951

这篇关于如何在GitHub Actions表达式语法中引用上下文值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆