JENKINS_GIT_DNS cicd network_error ai_generated true

标准错误:致命错误:无法访问 'https://github.com/org/repo.git/':无法解析主机:github.com

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

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

其他格式: JSON · Markdown 中文 · English
82%修复率
85%置信度
1证据数
2024-02-10首次发现

版本兼容性

版本状态引入弃用备注
Jenkins 2.440.x active
Jenkins 2.450.x active
Git plugin 5.2.x active

根因分析

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

English

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

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 70% 失败

    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% 失败

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