JENKINS_GIT_DNS cicd network_error ai_generated true

stderr: fatal: unable to access 'https://github.com/org/repo.git/': Could not resolve host: github.com

ID: cicd/jenkins-pipeline-git-checkout-failed

Also available as: JSON · Markdown · 中文
82%Fix Rate
85%Confidence
1Evidence
2024-02-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Jenkins 2.440.x active
Jenkins 2.450.x active
Git plugin 5.2.x active

Root Cause

Jenkins pipeline fails to clone a Git repository because the Jenkins agent cannot resolve the hostname due to DNS misconfiguration, network proxy settings, or the agent being in a restricted network environment.

generic

中文

Jenkins 管道无法克隆 Git 仓库,因为 Jenkins 代理由于 DNS 配置错误、网络代理设置或代理处于受限网络环境中而无法解析主机名。

Official Documentation

https://www.jenkins.io/doc/book/pipeline/scm/

Workarounds

  1. 85% success Configure the Jenkins agent to use a specific DNS server by setting JVM arguments: `-Djava.security.policy=/path/to/policy -Dnetworkaddress.cache.ttl=60` and ensure the agent's `/etc/resolv.conf` contains valid DNS servers like `8.8.8.8`.
    Configure the Jenkins agent to use a specific DNS server by setting JVM arguments: `-Djava.security.policy=/path/to/policy -Dnetworkaddress.cache.ttl=60` and ensure the agent's `/etc/resolv.conf` contains valid DNS servers like `8.8.8.8`.
  2. 80% success If behind a proxy, configure Git to use the proxy: `git config --global http.proxy http://proxy.example.com:8080` and `git config --global https.proxy http://proxy.example.com:8080` in the pipeline script before checkout.
    If behind a proxy, configure Git to use the proxy: `git config --global http.proxy http://proxy.example.com:8080` and `git config --global https.proxy http://proxy.example.com:8080` in the pipeline script before checkout.

中文步骤

  1. Configure the Jenkins agent to use a specific DNS server by setting JVM arguments: `-Djava.security.policy=/path/to/policy -Dnetworkaddress.cache.ttl=60` and ensure the agent's `/etc/resolv.conf` contains valid DNS servers like `8.8.8.8`.
  2. If behind a proxy, configure Git to use the proxy: `git config --global http.proxy http://proxy.example.com:8080` and `git config --global https.proxy http://proxy.example.com:8080` in the pipeline script before checkout.

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Adding `github.com` to the `/etc/hosts` file on the agent may work temporarily but fails if the IP address changes, and does not address the root cause of DNS resolution failure.

  2. 80% fail

    Changing the Git URL from HTTPS to SSH does not resolve DNS issues; SSH also requires hostname resolution and may introduce additional authentication failures.