使用 gitlab ci 调用curl命令时变量未扩展

问题描述 投票:0回答:1

我从 gitlab ci yml 文件调用以下curl 命令。 变量 jrun 没有得到扩展。

'curl "https://gitlab.com/api/v4/projects/454939/variables/$jrun" -H "Authorization: Bearer $GIT_SERVICE_TOKEN"'

echo "$jrun"
正确打印值
run1234

非常感谢在这方面的任何帮助。已在论坛中搜索并尝试了不同的选项。

尝试了各种选择:

'curl https://gitlab.com/api/v4/projects/454939/variables/"$jrun" -H "Authorization: Bearer $GIT_SERVICE_TOKEN"'
'curl "https://gitlab.com/api/v4/projects/454939/variables/$jrun" -H "Authorization: Bearer $GIT_SERVICE_TOKEN"'

将命令定义为变量Jcommand:

'curl "https://gitlab.com/api/v4/projects/454939/variables/$jrun" -H "Authorization: Bearer $GIT_SERVICE_TOKEN"'

并尝试了

'eval "$Jcommand"'

bash shell curl gitlab
1个回答
0
投票

感谢您的所有回复和评论。

@nquincampoix - 此curl 命令位于 gitlab-ci yml 文件中。所以它必须以单引号开头。

所以这就是最终起作用的方法。 将完全展开的 url 传递给curl 命令。我使用以下内容来扩展网址。

  • url =“https://gitlab.com/api/v4/projects/45482939/variables/${jrun}”
  • xUrl = $url
  • 'curl "$xUrl" -H "授权:持有者 $GIT_SERVICE_TOKEN"'
© www.soinside.com 2019 - 2024. All rights reserved.