Jenkins: Fall back to stashed data if the node can't reach github
This commit is contained in:
65
.ci/Jenkinsfile
vendored
65
.ci/Jenkinsfile
vendored
@@ -98,37 +98,48 @@ def gitClone(repository, branch) {
|
|||||||
/* Clean workspace. */
|
/* Clean workspace. */
|
||||||
cleanWs()
|
cleanWs()
|
||||||
|
|
||||||
/* Use stashes to pass the repository around debian.citadel, as it's known to be faster than git clone there. */
|
/* Perform git clone if stashed data isn't available yet, or if
|
||||||
if (env.NODE_NAME != 'debian.citadel' || env.GIT_STASHED != 'true') {
|
this is not debian.citadel where stash is faster than clone. */
|
||||||
/* Perform clone/checkout, making sure to update the changelog only once
|
if (env.GIT_STASHED != 'true' || env.NODE_NAME != 'debian.citadel') {
|
||||||
to avoid inaccurate entries from new commits pushed inbetween clones. */
|
/* Catch network issues in clone. */
|
||||||
def scmVars = checkout poll: true,
|
try {
|
||||||
changelog: env.GIT_STASHED != 'true',
|
/* Perform clone/checkout, making sure to update the changelog only once
|
||||||
scm: [$class: 'GitSCM',
|
to avoid inaccurate entries from new commits pushed inbetween clones. */
|
||||||
branches: [[name: branch]],
|
def scmVars = checkout(poll: true,
|
||||||
userRemoteConfigs: [[url: repository]]]
|
changelog: env.GIT_STASHED != 'true',
|
||||||
|
scm: [$class: 'GitSCM',
|
||||||
|
branches: [[name: branch]],
|
||||||
|
userRemoteConfigs: [[url: repository]]])
|
||||||
|
|
||||||
if (env.GIT_COMMIT == null) {
|
if (env.GIT_COMMIT == null) {
|
||||||
/* Save the current HEAD commit. */
|
/* Save the current HEAD commit. */
|
||||||
env.GIT_COMMIT = scmVars.GIT_COMMIT
|
env.GIT_COMMIT = scmVars.GIT_COMMIT
|
||||||
} else if (env.GIT_COMMIT != scmVars.GIT_COMMIT) {
|
} else if (env.GIT_COMMIT != scmVars.GIT_COMMIT) {
|
||||||
/* Checkout the commit read from the polling log. */
|
/* Checkout the commit read from the polling log. */
|
||||||
if (isUnix())
|
if (isUnix())
|
||||||
sh(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}")
|
sh(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}")
|
||||||
else
|
else
|
||||||
bat(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}")
|
bat(returnStatus: true, script: "git checkout ${env.GIT_COMMIT}")
|
||||||
}
|
}
|
||||||
println "[-] Using git commit [${env.GIT_COMMIT}]"
|
println "[-] Using git commit [${env.GIT_COMMIT}]"
|
||||||
|
|
||||||
/* Stash data and mark it as stashed if required. */
|
/* Stash data if required, marking it as stashed. */
|
||||||
if (env.GIT_STASHED != 'true') {
|
if (env.GIT_STASHED != 'true') {
|
||||||
stash name: 'git', useDefaultExcludes: false
|
stash(name: 'git', useDefaultExcludes: false)
|
||||||
env.GIT_STASHED = 'true'
|
env.GIT_STASHED = 'true'
|
||||||
|
}
|
||||||
|
|
||||||
|
/* No need to use stashed data. */
|
||||||
|
return;
|
||||||
|
} catch (e) {
|
||||||
|
/* If clone fails, use stashed data if available, or re-throw exception otherwise. */
|
||||||
|
if (env.GIT_STASHED != 'true')
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
/* Unstash data. */
|
|
||||||
unstash name: 'git'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Unstash data. */
|
||||||
|
unstash(name: 'git')
|
||||||
}
|
}
|
||||||
|
|
||||||
def removeDir(dir) {
|
def removeDir(dir) {
|
||||||
|
Reference in New Issue
Block a user