为什么gitlab-runner无法克隆我的项目? (主机名不正确,连接失败)

时间:2017-12-07 12:25:16

标签: git gitlab gitlab-ci gitlab-ci-runner

我设置了一个Gitlab服务器,需要使用gitlab-runner.exe运行Windows测试。

gitlab-runner的执行者设置为shellconfig.toml看起来像

concurrent = 1
check_interval = 0

[[runners]]
  name = "PC123"
  url = "http://1.2.3.4/ci"
  token = "cd2b093adc5ca09ea41ee4eadb0752"
  executor = "shell"
  [runners.cache]

在提交时生成测试时,

失败
Cloning into 'C:/git/builds/ac70aeb9/0/test/myproject'...
fatal: unable to access 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@localhost/test/boundaries.git/': Failed to connect to localhost port 80: Connection refused

我认为问题是主机名" localhost"在URL中,它指的是机器gitlab-runner所在。当我在开始时设置服务器时,我使用了#localhost'作为服务器主机名。这可能不是最好的主意。 :)

与此同时,我改变了这个" localgit",但URL没有调整,它仍然显示" localhost"。 (服务器重启,gitlab-runner servive重启)。

当主机名仍为localhost时,服务器的主机名是否存储在我克隆的原始仓库中的某个位置? .git/config显示正确的IP:

[remote "origin"]
    url = http://1.2.3.4/test/myproject.git

我发现另一个问题(GitLab runner unable to clone repository via http)提到了将其他主机添加到gitlab-runner config.toml的方法,比如

[runners.docker]
    extra_hosts = ["ci.mygitlab:127.0.0.1"]

但我必须使用shell执行者,而不是docker。

2 个答案:

答案 0 :(得分:3)

正如here所述,解决方案是将Gitlab配置文件host: localhost中的条目/home/git/gitlab/config/gitlab.yml替换为主机的IP地址。

更换前:

  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: localhost

更换后:

  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 10.0.1.2

答案 1 :(得分:0)

Omnibus软件包安装

如果您使用Omnibus软件包安装了GitLab,则需要确保external_url中的/etc/gitlab/gitlab.rb设置为主机的主机名或IP地址。使用localhost似乎会导致冲突,导致您描述的错误。这是一个示例:

## Correct
external_url 'http://192.168.0.2:8080'
## -or-
## external_url 'http://myhostname.com

## Incorrect
external_url 'http://localhost:8080'

更正了external_url之后,您需要使用以下命令重新配置GitLab:

gitlab-ctl reconfigure