GIT_CHECKOUT_FAILED cicd build_error ai_generated true

hudson.plugins.git.GitException: Could not checkout branch 'main' with start point 'origin/main'

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

Also available as: JSON · Markdown · 中文
84%Fix Rate
86%Confidence
1Evidence
2024-04-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Jenkins 2.440 active
Git Plugin 5.2.0 active
Git 2.40 active

Root Cause

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.

generic

中文

Jenkins Git插件无法检出,因为分支或提交引用丢失、远程仓库不可达,或工作空间存在之前中止构建的陈旧锁文件。

Official Documentation

https://plugins.jenkins.io/git/

Workarounds

  1. 85% success Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
    Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
  2. 90% success 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]])`
    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]])`
  3. 88% success Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script
    Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script

中文步骤

  1. Clean workspace and retry: add `cleanWs()` in pipeline or `git clean -fdx` before checkout, and ensure branch exists: `git branch -r | grep origin/main`
  2. 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]])`
  3. Force fetch remote refs before checkout: `git fetch origin +refs/heads/main:refs/remotes/origin/main --force` in pipeline script

Dead Ends

Common approaches that don't work:

  1. 50% fail

    Workspace deletion alone doesn't fix remote connectivity issues or stale git refs; lock files may reoccur.

  2. 70% fail

    Plugin reinstall doesn't affect remote repo state or local git configuration; overkill for checkout issue.

  3. 60% fail

    Timeout increase doesn't resolve missing branches or authentication failures; only delays failure.