我想在GitHub Action的env:
部分设置一个环境变量,并利用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 )
我知道如何在GitHub Actions中设置环境变量的解决方案:如何使用Bash表达式设置环境变量? 和 如何在Github Actions中共享计算值以在作业步骤之间传递参数?,但我想了解这些表达式的语法。
${{
内部放置了${{
?同时请注意,format
采用从0开始的索引。 - jonrsharpe${{}
。我猜你想要${{ format('{0}:{1}', env.PATH env.HOME) }}
。 - jonrsharpe