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

Why can't gitlab-runner clone my project? (Incorrect hostname, failed to connect)

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

gitlab-运行ner的executor设置为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

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

同时我改了这个"localgit",但是URL没有调整,还是显示"localhost"。 (服务器重启,gitlab-运行ner servive restart).

可能是服务器的主机名存储在我在主机名仍然是 localhost 时克隆的原始存储库中的某个地方? .git/config 显示正确的 IP:

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

我发现另一个问题()提到了一种将其他主机添加到gitlab的方法-运行ner的config.toml,喜欢

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

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

here所述,解决方案是将Gitlab配置文件/home/git/gitlab/config/gitlab.yml中的条目host: localhost替换为主机的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

综合包安装

如果您使用 Omnibus 软件包安装了 GitLab,则需要确保 /etc/gitlab/gitlab.rb 中的 external_url 设置为主机主机名或 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