Skip to content

Commit

Permalink
Workaround for Git #27287 is still required
Browse files Browse the repository at this point in the history
  • Loading branch information
ao-apps committed May 12, 2022
1 parent ca9a510 commit 5e22069
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 4 deletions.
57 changes: 55 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -651,19 +651,72 @@ pipeline {
}
}
}
stage('Checkout SCM') {
stage('Workaround Git #27287') {
when {
expression {
return (
currentBuild.result == null
|| currentBuild.result == hudson.model.Result.SUCCESS
|| currentBuild.result == hudson.model.Result.UNSTABLE
)
) && projectDir != '.' && fileExists('.gitmodules')
}
}
steps {
// See https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/#checkout-check-out-from-version-control
// See https://stackoverflow.com/questions/43293334/sparsecheckout-in-jenkinsfile-pipeline
/*
* Git version 2.34.1 is failing when fetching without submodules, which is our most common usage.
* It fails only on the first fetch, then succeeds on subsequent fetches.
* This issue is expected to be resolved in 2.35.1.
*
* To workaround this issue, we are allowing to retry the Git fetch by catching the first failure.
*
* See https://github.com/git/git/commit/c977ff440735e2ddc2ef18b18ae9a653bb8650fe
* See https://gitlab.com/gitlab-org/gitlab/-/issues/27287
*
* TODO: Remove once on Git >= 2.35.1
*/
catchError(message: 'Git 2.34.1 first fetch fails when not fetching submodules, will retry', buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[
url: scmUrl,
refspec: "+refs/heads/$scmBranch:refs/remotes/origin/$scmBranch"
]],
branches: [[name: "refs/heads/$scmBranch"]],
browser: scmBrowser,
extensions: [
// CleanCheckout was too aggressive and removed the workspace .m2 folder, added "sh" steps below
// [$class: 'CleanCheckout'],
[$class: 'CloneOption',
// See https://issues.jenkins.io/browse/JENKINS-45586
shallow: true,
depth: 20,
honorRefspec: true
],
[$class: 'SparseCheckoutPaths',
sparseCheckoutPaths: sparseCheckoutPaths
],
[$class: 'SubmoduleOption',
disableSubmodules: disableSubmodules,
shallow: true,
depth: 20
]
]
]
}
}
}
stage('Checkout SCM') {
when {
expression {
return (
currentBuild.result == null
|| currentBuild.result == hudson.model.Result.SUCCESS
|| currentBuild.result == hudson.model.Result.UNSTABLE
)
}
}
steps {
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[
url: scmUrl,
Expand Down
57 changes: 55 additions & 2 deletions book/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -622,19 +622,72 @@ pipeline {
}
}
}
stage('Checkout SCM') {
stage('Workaround Git #27287') {
when {
expression {
return (
currentBuild.result == null
|| currentBuild.result == hudson.model.Result.SUCCESS
|| currentBuild.result == hudson.model.Result.UNSTABLE
)
) && projectDir != '.' && fileExists('.gitmodules')
}
}
steps {
// See https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/#checkout-check-out-from-version-control
// See https://stackoverflow.com/questions/43293334/sparsecheckout-in-jenkinsfile-pipeline
/*
* Git version 2.34.1 is failing when fetching without submodules, which is our most common usage.
* It fails only on the first fetch, then succeeds on subsequent fetches.
* This issue is expected to be resolved in 2.35.1.
*
* To workaround this issue, we are allowing to retry the Git fetch by catching the first failure.
*
* See https://github.com/git/git/commit/c977ff440735e2ddc2ef18b18ae9a653bb8650fe
* See https://gitlab.com/gitlab-org/gitlab/-/issues/27287
*
* TODO: Remove once on Git >= 2.35.1
*/
catchError(message: 'Git 2.34.1 first fetch fails when not fetching submodules, will retry', buildResult: 'SUCCESS', stageResult: 'UNSTABLE') {
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[
url: scmUrl,
refspec: "+refs/heads/$scmBranch:refs/remotes/origin/$scmBranch"
]],
branches: [[name: "refs/heads/$scmBranch"]],
browser: scmBrowser,
extensions: [
// CleanCheckout was too aggressive and removed the workspace .m2 folder, added "sh" steps below
// [$class: 'CleanCheckout'],
[$class: 'CloneOption',
// See https://issues.jenkins.io/browse/JENKINS-45586
shallow: true,
depth: 20,
honorRefspec: true
],
[$class: 'SparseCheckoutPaths',
sparseCheckoutPaths: sparseCheckoutPaths
],
[$class: 'SubmoduleOption',
disableSubmodules: disableSubmodules,
shallow: true,
depth: 20
]
]
]
}
}
}
stage('Checkout SCM') {
when {
expression {
return (
currentBuild.result == null
|| currentBuild.result == hudson.model.Result.SUCCESS
|| currentBuild.result == hudson.model.Result.UNSTABLE
)
}
}
steps {
checkout scm: [$class: 'GitSCM',
userRemoteConfigs: [[
url: scmUrl,
Expand Down

0 comments on commit 5e22069

Please sign in to comment.