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

- **ID:** `cicd/jenkins-pipeline-git-checkout-failed`
- **领域:** cicd
- **类别:** network_error
- **错误码:** `JENKINS_GIT_DNS`
- **验证级别:** ai_generated
- **修复率:** 82%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Jenkins 2.440.x | active | — | — |
| Jenkins 2.450.x | active | — | — |
| Git plugin 5.2.x | active | — | — |

## 解决方案

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.
   ```

## 无效尝试

- **** — 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. (70% 失败率)
- **** — Changing the Git URL from HTTPS to SSH does not resolve DNS issues; SSH also requires hostname resolution and may introduce additional authentication failures. (80% 失败率)
