Cannot push from gitlab-ci.yml

后端 未结 3 1559
礼貌的吻别
礼貌的吻别 2020-12-23 12:18

With my colleagues, we work on a C++ library that becomes more and more important each day. We already built continuous integration utilities through the gitlab-ci.yml

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 12:27

    While the previous answers are more or less fine, there are some important gotya's.

      before_script:
        - git config --global user.name "${GITLAB_USER_NAME}"
        - git config --global user.email "${GITLAB_USER_EMAIL}"
      script:
        - 
        - git push "https://${GITLAB_USER_NAME}:${CI_GIT_TOKEN}@${CI_REPOSITORY_URL#*@}" "HEAD:${CI_COMMIT_TAG}"
    

    For one, we only need to set the username/email to please git.

    Secondly having it in the before script, is not super crucial, but allows for easier reuse when doing 'extend'.

    Finally, pushing https is 'fine' but since we're not using a stored ssh key, we should avoid anything that can reveal the token. For one, while gitlab won't print the token in this command, git will happily inform us that the new upstream is set to https://username:thetokeninplaintexthere@url So there's your token in plain text, so don't use -u to set an upstream.

    Also, it's not needed, we are only doing a single push.

    Further more, when determining the URL, I found that using the exist CI_REPOSITORY_URL to be the most reliable solution (when moving repo's for example or whatnot). So we just replace the username/token in the URL string.

提交回复
热议问题