【问题标题】:Gitlab-ci won't replace my variable in the ssh commandGitlab-ci 不会在 ssh 命令中替换我的变量
【发布时间】:2019-07-14 21:14:39
【问题描述】:

在我的 gitlab-ci.yml 中,我有一个通过 curl 帖子在 gitlab 中创建发布的命令

# create release
    - >- 
        curl --request POST -H 'PRIVATE-TOKEN: ${GITLABAPI_TOKEN}' -H 'Content-Type: application/json' --data "{\"description\": \"`git log $(git describe --tags --abbrev=0)..HEAD --oneline`\"}" https://gitlab.unc.nc/api/v4/projects/${APP_GITLAB_NUMBER}/repository/tags/${CI_COMMIT_TAG}/release

此请求得到“401 未授权”,因为我怀疑 -H 'PRIVATE-TOKEN: ${GITLABAPI_TOKEN}' 没有被变量值替换。 与:${GITLABAPI_TOKEN} $GITLABAPI_TOKEN "${GITLABAPI_TOKEN}"

相同

如果我这样显示值,值就ok了:

 ssh root@devsb01 "echo $GITLABAPI_TOKEN"

如果我直接使用密码值启动帖子,它会起作用:

    - >- 
        curl --request POST -H 'PRIVATE-TOKEN: xkwMyRealPwdùwsx' -H 'Content-Type: application/json' --data "{\"description\": \"`git log $(git describe --tags --abbrev=0)..HEAD --oneline`\"}" https://gitlab.unc.nc/api/v4/projects/${APP_GITLAB_NUMBER}/repository/tags/${CI_COMMIT_TAG}/release

我想我需要在命令中添加一些内容以便替换它...但我不能...

PS:请注意,url 变量:${APP_GITLAB_NUMBER} 和 ${CI_COMMIT_TAG} 已正确替换

【问题讨论】:

    标签: curl gitlab-ci


    【解决方案1】:

    在单引号内,shell 不扩展任何内容。请将 PRIVATE-TOKEN 放入双引号中:

    curl --request POST -H "PRIVATE-TOKEN: ${GITLABAPI_TOKEN}" -H 'Content-Type: application/json' --data "{\"description\": \"`git log $(git describe --tags --abbrev=0)..HEAD --oneline`\"}" https://gitlab.unc.nc/api/v4/projects/${APP_GITLAB_NUMBER}/repository/tags/${CI_COMMIT_TAG}/release
    

    【讨论】:

      猜你喜欢
      • 2020-02-15
      • 2022-07-29
      • 2022-07-12
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      • 2022-01-15
      • 2021-07-04
      • 2021-10-13
      相关资源
      最近更新 更多