我想克隆GitLab仓库没有提示我的自动化脚本,通过使用我的私人令牌从我的GitLab帐户。
有人能给我一个样品吗?
我知道我可以这样做的用户和密码:
git clone https://" + user + ":" + password + "@" + gitlaburl;
我知道这是可能的ssh密钥
但是,这两种选择都不够。
我想克隆GitLab仓库没有提示我的自动化脚本,通过使用我的私人令牌从我的GitLab帐户。
有人能给我一个样品吗?
我知道我可以这样做的用户和密码:
git clone https://" + user + ":" + password + "@" + gitlaburl;
我知道这是可能的ssh密钥
但是,这两种选择都不够。
当前回答
现在(2020年10月),你可以只使用以下内容
git clone $CI_REPOSITORY_URL
它将扩展为如下内容:
git clone https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.git
其中“令牌”密码是临时令牌(它将在构建完成后自动撤销)。
其他回答
使用令牌而不是密码(令牌需要有“api”范围才能允许克隆):
git clone https://username:token@gitlab.com/user/repo.git
在11.0.0-ee上测试。
从8.12开始,不再支持使用HTTPS +运行令牌进行克隆,如下所述:
在8.12中,我们改进了构建权限。从现在开始不支持使用runner令牌克隆项目(它实际上是巧合,从来都不是一个完整的功能,所以我们在8.12中改变了这一点)。您应该使用构建令牌代替。 这是广泛记录在这里- https://docs.gitlab.com/ce/user/project/new_ci_build_permissions_model.html。
一种可能的方法是使用部署令牌 (https://docs.gitlab.com/ee/user/project/deploy_tokens)。创建令牌后,使用:
git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
如上面的链接所述。
你可以为你的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管道,并在页面上寻找跑步者令牌
跑步者令牌位置的截图:
gitlab有很多令牌:
私人的令牌 个人访问令牌 CI/CD运行令牌
我只测试了个人访问令牌使用GitLab社区版10.1.2,示例:
git clone https://gitlab-ci-token:${Personal Access Tokens}@gitlab.com/username/myrepo.git
git clone https://oauth2:${Personal Access Tokens}@gitlab.com/username/myrepo.git
或使用用户名和密码:
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
或输入您的密码:
git clone https://${username}@gitlab.com/username/myrepo.git
但是私有令牌似乎不能工作。