Gitlab运行程序无法使用ssh-agent

时间:2018-07-19 06:44:37

标签: gitlab git-submodules gitlab-ci-runner ssh-agent

我正在尝试使用Shell executor为我的项目(baseProject)配置gitlab-runner。我的项目有两个子模块:submoduleOne和submoduleTwo。 这就是我的.gitmodules的样子:

[submodule "lib/submoduleOne"]
path = lib/submoduleOne
url = ../submoduleOne.git
[submodule "third_party/submoduleTwo"]
path = third_party/submoduleTwo
url = ../submoduleTwo.git

这是我的.gitlab-ci.yml中相关部分的样子:

stages:
    - preparation
clean:
    stage: preparation
    script:
        - eval $(ssh-agent -s)
        - ssh-add ~/.ssh/submoduleOne
        - ssh-add -l
        - git submodule update --init -- lib/submoduleOne
        - ssh-add -D
        - ssh-add ~/.ssh/submoduleTwo
        - ssh-add -l
        - git submodule update --init -- third_party/submoduleTwo
        - ./setup_project.sh 

公共密钥~/.ssh/submoduleTwo~/.ssh/submoduleOne作为“部署密钥”添加到gitlab中的各个项目中,并且指纹匹配。这两个项目的配置方式似乎相同。

但是,作业失败,输出为:

Running with gitlab-runner 11.0.0 (5396d320)
  on wawsrvbuild70 3295e1f6
Using Shell executor...
Running on wawsrvbuild70...
Fetching changes...
HEAD is now at 5e3be99 CI test
From https://gitlab01.mydomain.pl/Group/baseProject
   5e3be99..0029318  p.czechows2/configure-gitlab-ci#1038 -> origin/p.czechows2/configure-gitlab-ci#1038
Checking out 00293180 as p.czechows2/configure-gitlab-ci#1038...
Skipping Git submodules setup
$ eval $(ssh-agent -s)
Agent pid 18755
$ ssh-add ~/.ssh/submoduleOne
Identity added: /home/gitlab-runner/.ssh/submoduleOne (/home/gitlab-runner/.ssh/submoduleOne)
$ ssh-add -l
4096 27:f5:e5:86:af:a7:7a:aa:52:03:b1:6d:05:72:56:29 /home/gitlab-runner/.ssh/submoduleOne (RSA)
$ git submodule update --init -- lib/submoduleOne
$ ssh-add -D
All identities removed.
$ ssh-add ~/.ssh/submoduleTwo
Identity added: /home/gitlab-runner/.ssh/submoduleTwo (/home/gitlab-runner/.ssh/submoduleTwo)
$ ssh-add -l
4096 89:aa:68:f9:88:72:4c:cf:8a:a3:c7:7e:34:92:91:6b /home/gitlab-runner/.ssh/submoduleTwo (RSA)
$ git submodule update --init -- third_party/submoduleTwo
Cloning into 'third_party/submoduleTwo'...
fatal: Authentication failed for 'https://gitlab-ci-token:yXkvnfXZadABF4FZWTSb@gitlab01.mydomain.pl/Group/submoduleTwo.git/'
Clone of 'https://gitlab-ci-token:yXkvnfXZadABF4FZWTSb@gitlab01.mydomain.pl/Group/submoduleTwo.git' into submodule path 'third_party/submoduleTwo' failed
ERROR: Job failed: exit status 1

这个令牌yXkvnfXZadABF4FZWTSb是我在为baseProject配置它时给gitlab-runner的令牌。但是我不确定在哪里检查。 同样,更改子模块初始化的顺序也无济于事:问题仍然在于submoduleTwo。 所以我的问题是:为什么gitlab-runner不会使用ssh-agent中存储的私钥来克隆此存储库?还是我在某个地方犯了错误?也欢迎提出有关如何在gitlab-runner中不同地配置子模块初始化的建议。

0 个答案:

没有答案