我想克隆GitLab仓库没有提示我的自动化脚本,通过使用我的私人令牌从我的GitLab帐户。
有人能给我一个样品吗?
我知道我可以这样做的用户和密码:
git clone https://" + user + ":" + password + "@" + gitlaburl;
我知道这是可能的ssh密钥
但是,这两种选择都不够。
我想克隆GitLab仓库没有提示我的自动化脚本,通过使用我的私人令牌从我的GitLab帐户。
有人能给我一个样品吗?
我知道我可以这样做的用户和密码:
git clone https://" + user + ":" + password + "@" + gitlaburl;
我知道这是可能的ssh密钥
但是,这两种选择都不够。
当前回答
你可以这样做:
git clone https://gitlab-ci-token:<private token>@git.example.com/myuser/myrepo.git
其他回答
你可以这样做:
git clone https://oauth2:ACCESS_TOKEN@somegitlab.com/vendor/package.git
为了让我的未来我快乐:RTFM -不要使用gitlab-ci-令牌,而是使用.netrc文件。
这里有几个要点:
echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc . 不要忘记用你的URL替换“gitlab.com”! 不要试图聪明,直接创建.netrc文件- gitlab不会替换文件中的$CI_JOB_TOKEN ! 使用https://gitlab.com/whatever/foobar.com -不是ssh://git@foobar,不是git+ssh://,不是git+https://.URL中也不需要任何CI-TOKEN。 确保你可以git clone [url from step 4]
背景:我有
fatal: could not read Username for 'https://gitlab.mycompany.com': No such device or address
当我试着让Ansible + Gitlab + Docker像我想象的那样工作时。现在它起作用了。
一种可能的方法是使用部署令牌 (https://docs.gitlab.com/ee/user/project/deploy_tokens)。创建令牌后,使用:
git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
如上面的链接所述。
我去SSH使用每个项目部署键设置(只读)
你可以为你的GitLab回购的CI/CD管道使用runner令牌。
git clone https://gitlab-ci-token:<runners token>@git.example.com/myuser/myrepo.git
<runners token>可以从:
git.example.com/myuser/myrepo/pipelines/settings
或通过点击设置图标-> CI/CD管道,并在页面上寻找跑步者令牌
跑步者令牌位置的截图: