You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用下划线拼接GitHub Actions中的多个变量并解决语法错误?

解决GitHub Actions变量拼接语法错误

正确实现方式

有两种简洁且合法的写法可以实现需求:

  1. 字符串拼接方式
- name: Call composite
  id: fixit
  uses: mybank/DevOps/integration@master
  with:
    ArrCall: ${{ inputs.backup_fileextension || steps.Deployment.outputs.newCO + '_' + steps.Deployment.outputs.formatdate + '_' + github.run_number }}
  1. 使用format函数(更推荐,可读性更高)
- name: Call composite
  id: fixit
  uses: mybank/DevOps/integration@master
  with:
    ArrCall: ${{ inputs.backup_fileextension || format('{0}_{1}_{2}', steps.Deployment.outputs.newCO, steps.Deployment.outputs.formatdate, github.run_number) }}

错误原因分析

  • 第一种尝试的问题:在${{ }}表达式内部额外用{}包裹变量({steps.Deployment.outputs.newCO})属于语法错误,GitHub Actions表达式中引用变量直接写变量名即可,不需要嵌套大括号;同时直接用_连接变量不是合法的字符串拼接语法,必须用+操作符连接字符串。
  • 第二种尝试的问题:使用了转义的双引号",换成单引号'即可避免语法识别问题,另外需确保steps.Deployment步骤已成功执行并输出了对应的newCO和formatdate值。

内容的提问来源于stack exchange,提问作者Ashar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 17:15:17