Github Actions中$GITHUB_OUTPUT设置变量后值为空的问题
GitHub Actions输出变量为空的解决方法
你的问题出在输出变量的格式上,echo "url= abc" >> $GITHUB_OUTPUT里的url=后面多了空格,GitHub Actions无法正确识别这个键值对,导致后续步骤取不到值。
正确的配置应该这样写:
name: Test Output Variable on: [push] jobs: test-variable: runs-on: ubuntu-latest steps: - name: Set variable id: init shell: bash run: | # 键值对之间不要加多余空格,值含空格的话用引号包裹 echo "url=abc" >> $GITHUB_OUTPUT # 如果值包含空格,可写成: # echo 'url="abc def"' >> $GITHUB_OUTPUT - name: Get variable shell: bash run: | echo "${{ steps.init.outputs.url }}"
关键注意点:
- 输出变量的键值对必须是
键=值格式,键和等号、等号和值之间不能有多余空格,否则会被判定为无效格式 - 如果值包含空格或特殊字符,需要用单/双引号将值包裹,保证GitHub Actions能正确解析
- 确保设置变量的步骤配置了正确的
id(示例中为init),后续步骤才能通过steps.{{id}}.outputs.{{键名}}正确引用变量
内容的提问来源于stack exchange,提问作者khaldrogo 91
相关产品推荐
相关产品推荐

