GIT_CHECKOUT_FAILED
cicd
build_error
ai_generated
true
Git插件异常:无法检出分支'main',起始点'origin/main'
hudson.plugins.git.GitException: Could not checkout branch 'main' with start point 'origin/main'
ID: cicd/jenkins-pipeline-checkout-failed-git
84%修复率
86%置信度
1证据数
2024-04-18首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Jenkins 2.440 | active | — | — | — |
| Git Plugin 5.2.0 | active | — | — | — |
| Git 2.40 | active | — | — | — |
根因分析
Jenkins Git插件无法检出,因为分支或提交引用丢失、远程仓库不可达,或工作空间存在之前中止构建的陈旧锁文件。
English
Jenkins Git plugin fails to checkout because the branch or commit reference is missing, the remote repository is unreachable, or the workspace has stale lock files from a previous aborted build.
官方文档
https://plugins.jenkins.io/git/解决方案
-
Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
-
Use shallow clone with depth 1 to avoid stale refs: `checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [[$class: 'CloneOption', depth: 1, noTags: true, shallow: true]])`
-
Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
无效尝试
常见但无效的做法:
-
50% 失败
Workspace deletion alone doesn't fix remote connectivity issues or stale git refs; lock files may reoccur.
-
70% 失败
Plugin reinstall doesn't affect remote repo state or local git configuration; overkill for checkout issue.
-
60% 失败
Timeout increase doesn't resolve missing branches or authentication failures; only delays failure.