gpt4 book ai didi

github-actions - 如何在GitHub Actions表达式语法中引用上下文值?

转载 作者:行者123 更新时间:2023-12-03 13:40:10 28 4
gpt4 key购买 nike

我想在GitHub Action的env:部分设置一个环境变量,并使用Contexts and expression syntax for GitHub Actions。我尝试了这个:

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 )

我知道 How do i set an env var with a bash expression in GitHub Actions?Github Actions, how to share a calculated value between job steps?中用于设置环境变量的解决方案,但是我想了解表达式语法。

最佳答案

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

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

关于github-actions - 如何在GitHub Actions表达式语法中引用上下文值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59809764/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com