我想通过使用我的gitlab帐户中的私有令牌来克隆gitlab存储库而不提示我的自动化脚本.
有人能为我提供样品吗?
我知道我可以使用用户和密码这样做:
git clone https://" + user + ":" + password + "@" + gitlaburl;
Run Code Online (Sandbox Code Playgroud)
我知道用ssh键是可能的
但是,这两种选择都不够
Ros*_*tam 144
我知道这是旧的,但这是你如何做到的:
git clone https://oauth2:ACCESS_TOKEN@somegitlab.com/vendor/package.git
Tim*_*hes 36
你可以这样做:
git clone https://gitlab-ci-token:<private token>@git.example.com/myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
xua*_*eng 28
gitlab有很多令牌:
我仅使用GitLab Community Edition 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
Run Code Online (Sandbox Code Playgroud)
或使用用户名和密码:
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
Run Code Online (Sandbox Code Playgroud)
或输入您的密码:
git clone https://${username}@gitlab.com/username/myrepo.git
Run Code Online (Sandbox Code Playgroud)
但私人令牌似乎无法奏效.
Zby*_*ler 20
使用令牌而不是密码(令牌需要具有允许克隆的"api"范围):
git clone https://username:token@gitlab.com/user/repo.git
Run Code Online (Sandbox Code Playgroud)
测试11.0.0-ee.
小智 14
您可以使用GitLab存储库的CI/CD管道的运行程序标记.
git clone https://gitlab-ci-token:<runners token>@git.example.com/myuser/myrepo.git
Run Code Online (Sandbox Code Playgroud)
哪里<runners token>可以从:
git.example.com/myuser/myrepo/pipelines/settings
Run Code Online (Sandbox Code Playgroud)
或者单击Settings icon -> CI/CD Pipeline并在页面上查找Runners Token
Rog*_*eto 10
如果您已经有一个存储库,并且只是更改了对MFA进行身份验证的方式,则可以更改remote originHTTP URI以使用新的api令牌,如下所示:
git remote set-url origin https://oauth2:TOKEN@ANY_GIT_PROVIDER_DOMAIN/YOUR_PROJECT/YOUR_REPO.git
您根本不需要重新克隆存储库。
由于8.12使用克隆HTTPS如前所述+令牌不再被支持,在这里:
在8.12中,我们改进了构建权限.能够使用跑步者令牌克隆项目从现在开始不支持它(它实际上是巧合而且从来不是一个完全成熟的功能,所以我们在8.12中改变了它).您应该使用构建令牌.
这在此广泛记录 - https://docs.gitlab.com/ce/user/project/new_ci_build_permissions_model.html.
这些天(2020 年 10 月)您可以使用以下内容
git clone $CI_REPOSITORY_URL
Run Code Online (Sandbox Code Playgroud)
这将扩展到类似:
git clone https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.git
Run Code Online (Sandbox Code Playgroud)
其中“令牌”密码是临时令牌(构建完成后将自动撤销)。
在GitLab CI管道中,CI_JOB_TOKEN环境变量对我有用:
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/...
Run Code Online (Sandbox Code Playgroud)
资料来源:Gitlab文件
顺便说一句,在中设置此变量.gitlab-ci.yml有助于调试错误。
variables:
CI_DEBUG_TRACE: "true"
Run Code Online (Sandbox Code Playgroud)
一种可能的方法是使用部署令牌(https://docs.gitlab.com/ee/user/project/deploy_tokens)。创建令牌后,使用:
git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
Run Code Online (Sandbox Code Playgroud)
如上面链接中所述。
上面的许多答案都很接近,但是他们得到username了deploy不正确的令牌语法。还有其他类型的令牌,但这deploy token是 gitlab 提供的(至少大约 2020 年以上)每个 repo以允许自定义访问,包括只读。
从repository(或group),找到settings--> repository--> deploy tokens。创建一个新的。Ausername和token字段已创建。在username默认情况下不固定值; 它是这个令牌的独特之处。
git clone https://<your_deploy_token_username>:<the_token>@gitlab.com/your/repo/path.git
在 gitlab.com 公共、免费帐户上测试。
为了让我的未来快乐:RTFM - 根本不使用 gitlab-ci-token,而是使用文件.netrc。
有几个要点:
echo -e "machine gitlab.com\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc$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
Run Code Online (Sandbox Code Playgroud)
当我试图让 Ansible + Gitlab + Docker 按照我的想象工作时。现在可以了。
| 归档时间: |
|
| 查看次数: |
109541 次 |
| 最近记录: |