Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I set-up a Gitlab server and need to run tests Windows using gitlab-runner.exe.

The gitlab-runner's executor is set to shell, the config.toml looks like

concurrent = 1
check_interval = 0

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

When the test is spawned on a commit it fails with

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

I suppose the problem is the hostname "localhost" in the URL, which refers to the machine gitlab-runner is on. When I set-up the server in the beginning I used 'localhost' as the servers hostname. This was probably not the best idea. :)

In the meantime I changed this "localgit", but the URL does not adjust, it still shows "localhost". (Server restarted, gitlab-runner servive restart).

Could it be that the server's hostname is stored somewhere in the original repo that I cloned when the hostname was still localhost? .git/config shows the correct IP:

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

I found another question (GitLab runner unable to clone repository via http) that mentions a way to add other hosts to gitlab-runner's config.toml, like

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

But I must use the shell executor, not docker.

like image 450
Joe Avatar asked Dec 07 '17 12:12

Joe


2 Answers

As described here, the solution is to replace the entry host: localhost in the Gitlab config file /home/git/gitlab/config/gitlab.yml with the IP address of the host.

Before replacing:

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

After replacing:

  gitlab:
    ## Web server settings (note: host is the FQDN, do not include http://)
    host: 10.0.1.2
like image 93
Joe Avatar answered Sep 27 '22 19:09

Joe


Omnibus package installation

If you've installed GitLab using the Omnibus package, you will need to ensure that external_url in /etc/gitlab/gitlab.rb is set to either the host machines hostname or IP address. Using localhost seems to cause a conflict that results in the error that you describe. Here's an example:

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

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

Once you've corrected the external_url, you'll need to reconfigure GitLab using the following command:

gitlab-ctl reconfigure
like image 27
JTW Avatar answered Sep 27 '22 17:09

JTW