Javid
Javid

Reputation: 2935

`unable to access 'XXX': Could not resolve host` Gitlab CI/CD pipeline

We have hosted Gitlab on a private dedicated server that can only be accessed through an L2TP VPN tunnel. The DNS of the domain is set to IP to the host in the internal network so obviously it's not accessible without the VPN. The problem is that when Gitlab CI/CD gets triggered, an error occurs in the job with the following log:

Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/web/XXX/.git/
fatal: unable to access 'https://<our domain>/web/XXX.git/': Could not resolve host: <our domain>

Heres .gitlab-ci.yml: image: docker/compose:latest

services:
  - docker:dind

before_script:
  - docker version
  - docker-compose --version
  - 'command -v ssh-agent >/dev/null || ( apt-get update -y && apt-get install openssh-client -y )'
  - eval $(ssh-agent -s)
  - echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -

build:
  stage: build
  script:
    - docker-compose --context remote up -d --build

It seems like it can't find IP of the host. I don't even know where to start to diagnose the problem. In the hosting server I pinged the host address and it displayed the correct IP address. How can I fix this?

Upvotes: 3

Views: 12000

Answers (1)

Sourav
Sourav

Reputation: 3392

This error is because the host is not known docker.

The same issue has been occurred to me as well. I have added the domain name and domain ip in extra_hosts parameter under docker executor configuration in config.toml

Get the ip address of the host you are trying to add, as you need to add both hostname and host ip in extra_hosts parameter.

In your config.toml, change like this:

[[runners]]
  name = "maven-docker"
  url = "https://<your-domain-name>/gitlab/"
  token = "MXvXVma55_Kw2o"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.docker]
    tls_verify = false
    image = "maven:latest"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    extra_hosts = ["<your-domain-name>:<your-domain-ip>"]
    pull_policy = "never"
    shm_size = 0
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.custom]
    run_exec = ""

Then, restart the gitlab runner using command sudo gitlab-runner restart or gitlab-runner restart

Upvotes: 4

Related Questions