使用GitLab令牌进行克隆而不进行身份验证
我想使用我的GitLab帐户中的私有令牌克隆GitLab存储库,而不提示输入我的自动化脚本 有人能给我一个样品吗 我知道我可以使用用户和密码执行此操作:使用GitLab令牌进行克隆而不进行身份验证,gitlab,Gitlab,我想使用我的GitLab帐户中的私有令牌克隆GitLab存储库,而不提示输入我的自动化脚本 有人能给我一个样品吗 我知道我可以使用用户和密码执行此操作: git clone https://" + user + ":" + password + "@" + gitlaburl; git clone https://${username}:${password}@gitlab.com/username/myrepo.git git clone
git clone https://" + user + ":" + password + "@" + gitlaburl;
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
git clone https://${username}@gitlab.com/username/myrepo.git
我知道使用ssh密钥是可能的
但是,这两种选择都是不够的。我知道这很旧,但你就是这样做的:
git clone
您可以这样做:
git clone https://gitlab-ci-token:<private token>@git.example.com/myuser/myrepo.git
git克隆https://gitlab-ci-token:@git.example.com/myuser/myrepo.git
您可以将runners令牌用于GitLab repo的CI/CD管道
git clone https://gitlab-ci-token:<runners token>@git.example.com/myuser/myrepo.git
或者单击设置图标->CI/CD管道
并在页面上查找Runners令牌
跑步者令牌位置的屏幕截图:
自
8.12
起,不再支持使用HTTPS
+runner令牌进行克隆,如上所述:
在8.12中,我们改进了构建权限。从现在起,无法使用runners标记克隆项目(这实际上是巧合,从来不是一个完全成熟的功能,所以我们在8.12中对此进行了更改)。您应该改用构建令牌
这在这里有广泛的记录-
我使用每个项目部署密钥设置(只读)使用SSH。gitlab有很多令牌:
- 私人代币
- 个人访问令牌
- CI/CD运行令牌
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://" + user + ":" + password + "@" + gitlaburl;
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
git clone https://${username}@gitlab.com/username/myrepo.git
或输入您的密码:
git clone https://" + user + ":" + password + "@" + gitlaburl;
git clone https://${username}:${password}@gitlab.com/username/myrepo.git
git clone https://${username}@gitlab.com/username/myrepo.git
但是,专用令牌似乎无法工作。使用令牌而不是密码(令牌需要具有允许克隆的“api”范围):
针对11.0.0-ee进行测试。在GitLab CI管道中,
CI\u作业\u令牌
环境变量对我有效:
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/...
资料来源:
顺便说一句,在.gitlab ci.yml
中设置此变量有助于调试错误
variables:
CI_DEBUG_TRACE: "true"
一种可能的方法是使用部署令牌 (). 创建令牌后,请使用:
git clone https://<username>:<deploy_token>@gitlab.example.com/tanuki/awesome_project.git
git clone https://:@gitlab.example.com/tanuki/awesome_project.git
如上面的链接所述。如果您已经有了一个存储库,并且刚刚更改了对MFA进行身份验证的方式,您可以更改您的
远程源
HTTP URI以使用新的api令牌,如下所示:
git远程设置url源https://oauth2:TOKEN@任何GIT提供商\u域/您的\u项目/您的\u REPO.GIT
而且您根本不需要重新克隆存储库。为了让我的未来快乐:-不要使用gitlab ci令牌,而是使用
.netrc
文件
这里有几个要点:
echo-e“machine gitlab.com\nlogin gitlab ci token\n密码${ci\u JOB\u token}>~/.netrc
$CI\u JOB\u令牌
李>
https://gitlab.com/whatever/foobar.com
-非ssh://git@foobar
,而不是git+ssh://
,而不是git+https://
。URL中也不需要任何CI-TOKEN内容git克隆[步骤4中的url]
fatal: could not read Username for 'https://gitlab.mycompany.com': No such device or address
当我试图让Ansible+Gitlab+Docker按我想象的那样工作时。现在它可以工作了。不需要自定义URL。只需对gitlab令牌使用git配置,例如
git config --global gitlab.accesstoken {TOKEN_VALUE}
上面的许多答案很接近,但它们得到的
username
语法对于deploy
令牌是不正确的。还有其他类型的代币,但gitlab为每个回购提供了(deploy token
),以允许定制访问,包括只读访问
从存储库
(或组
)中,找到设置
-->存储库
-->部署令牌
。创建一个新的。将创建用户名
和令牌
字段。默认情况下,用户名
不是固定值;这是这个令牌所独有的
git clone https://:@gitlab.com/your/repo/path.git
在gitlab.com公共免费帐户上测试。现在(2020年10月),您可以使用以下工具
git clone$CI\u REPOSITORY\u URL
这将扩展到如下内容:
git克隆https://gitlab-ci-token:[屏蔽]@gitlab.com/gitlab-examples/ci-debug-trace.git
如果“令牌”密码是临时令牌,则应在生成完成后将其撤销。这似乎是正确的,但对我来说,它总是无法通过身份验证:(对我来说也是:致命的:身份验证失败,因为需要用CI runner的令牌而不是帐户的私有令牌来替换。我认为您还应该能够正确使用您的个人令牌@TIM您可以使用特定于项目的CI令牌(启用生成,然后转到项目/runner配置)。这在GitLab 8.5.7企业版上对我有效。在这里有效(GitLab Community Edition 8.16.5 064dab1)。它有效!我想知道为什么在GitLab.com的项目详细信息上,他们没有给出完整的命令语法:-((如何通过
ssh
?即使read\u api
和write\u api
权限都不够。您必须拥有api
。注意:runners令牌现在已被弃用。@ArihantGodha source?@miq see(截至>=8.12)此格式现在已被弃用,请参阅无法从GitLab CI管道内部工作。但这行代码可以工作:git clonehttps://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/…
不可能使用runners代币,但使用的是个人访问代币。请参阅我的答案:@MuhanAlim我建议任何人不要使用访问代币公开他们的整个帐户。这就是为什么他们被称为私人访问代币的原因!问题没有提到任何关于公开密钥的内容,只提到如何在pla中使用密钥用户名和密码的ce