我想克隆GitLab仓库没有提示我的自动化脚本,通过使用我的私人令牌从我的GitLab帐户。

有人能给我一个样品吗?

我知道我可以这样做的用户和密码:

git clone https://" + user + ":" + password + "@" + gitlaburl;

我知道这是可能的ssh密钥

但是,这两种选择都不够。


当前回答

为了让我的未来我快乐: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像我想象的那样工作时。现在它起作用了。

其他回答

使用令牌而不是密码(令牌需要有“api”范围才能允许克隆):

git clone https://username:token@gitlab.com/user/repo.git

在11.0.0-ee上测试。

在本例中,我只提供了令牌而不是密码(第二个输入字段)。

我第一次从命令行推送本地回购。

从头开始,这些是我输入的命令(记得先移动到回购文件夹内)。

$ git init

$ git status

$ git add .

$ git status

$ git commit -m 'Shinra Tensei.'

$ git push --set-upstream https://gitlab.com/userName/my-repo.git master

然后,您可以在图片中看到的弹出消息出现。提供用户名和令牌。

现在(2020年10月),你可以只使用以下内容

git clone $CI_REPOSITORY_URL

它将扩展为如下内容:

git clone https://gitlab-ci-token:[MASKED]@gitlab.com/gitlab-examples/ci-debug-trace.git

其中“令牌”密码是临时令牌(它将在构建完成后自动撤销)。

您可以更改您的:

user:oauth2
password : <youraccesstoken>

例子:

git clone https://oauth2:<token>@hahahehe.com/yourname/yourproject.git

在GitLab CI管道中,CI_JOB_TOKEN环境变量为我工作:

git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/...

来源:Gitlab Docs

顺便说一下,在.gitlab-ci中设置这个变量。Yml有助于调试错误。

variables:
    CI_DEBUG_TRACE: "true"