Need an alternative way to checkout because git plugin is not working when using LFS and sparse checkout simultaneously

This commit is contained in:
Dan Hawkins 2019-05-14 09:11:38 +01:00
commit 6b9f624770

View file

@ -90,6 +90,91 @@ def checkgitlfsinstall() {
}
}
def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
checkgitlfsinstall()
def reporootpath = checkouttoreporoot(gitURL)
if (!sparseitemlist.isEmpty()) {
def itemstring = "Items in sparse item list:\n"
for (item in sparseitemlist) {
itemstring += item + "\n"
}
echo itemstring
}
checkout([
$class: 'GitSCM',
userRemoteConfigs: [
[url: gitURL]
],
branches: [
[name: revision]
],
doGenerateSubmoduleConfigurations: false,
extensions: [
[$class: 'GitLFSPull'],
[$class: 'CleanBeforeCheckout'],
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: reporootpath, shallow: shallowClone, timeout: 120],
[$class: 'CheckoutOption', timeout: 120],
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir],
[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: sparsecheckoutconfig(sparseitemlist)],
],
submoduleCfg: [],
])
}
//No credentials specified
//Cloning the remote Git repository
//Cloning repository git@hydra:print-server-releases/print_server_whole.git
//> git init /home/jenkins_user/jenkins/jobs/Print_Server_publish_to_customer/ws/whole # timeout=10
//Using reference repository: /home/jenkins_user/reporoot/git_hydra_print_server_releases_print_server_whole_git
//Fetching upstream changes from git@hydra:print-server-releases/print_server_whole.git
// > git --version # timeout=10
// > git fetch --tags --progress git@hydra:print-server-releases/print_server_whole.git +refs/heads/*:refs/remotes/origin/* # timeout=120
// > git config remote.origin.url git@hydra:print-server-releases/print_server_whole.git # timeout=10
// > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
// > git config remote.origin.url git@hydra:print-server-releases/print_server_whole.git # timeout=10
// Cleaning workspace
// > git rev-parse --verify HEAD # timeout=10
// No valid HEAD. Skipping the resetting
// > git clean -fdx # timeout=10
// Fetching upstream changes from git@hydra:print-server-releases/print_server_whole.git
// > git fetch --tags --progress git@hydra:print-server-releases/print_server_whole.git +refs/heads/*:refs/remotes/origin/* # timeout=120
// > git rev-parse refs/tags/2.10180.7389.21125_7^{commit} # timeout=10
// > git rev-parse refs/remotes/origin/refs/tags/2.10180.7389.21125_7^{commit} # timeout=10
// Checking out Revision 64cac35e9a7603c060135f61f91b3f809bbdf160 (refs/tags/2.10180.7389.21125_7)
// Enabling Git LFS pull
// > git config core.sparsecheckout # timeout=10
// > git checkout -f 64cac35e9a7603c060135f61f91b3f809bbdf160 # timeout=120
// > git config --get remote.origin.url # timeout=10
// > git lfs pull origin # timeout=120
// Commit message: "2.10180.7389.21125_7"
// > git rev-list --no-walk 64cac35e9a7603c060135f61f91b3f809bbdf160 # timeout=10
// > git rev-parse --is-inside-work-tree # timeout=10
// Fetching changes from the remote Git repository
// > git config remote.origin.url git@hydra:releases/print-server-installer.git # timeout=10
// Cleaning workspace
// > git rev-parse --verify HEAD # timeout=10
// Resetting working tree
// > git reset --hard # timeout=10
// > git clean -fdx # timeout=10
// Using shallow fetch with depth 1
// Fetching upstream changes from git@hydra:releases/print-server-installer.git
// > git --version # timeout=10
// > git fetch --tags --progress git@hydra:releases/print-server-installer.git +refs/heads/*:refs/remotes/origin/* --depth=1 # timeout=120
// > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
// > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
// Checking out Revision d0788d22622862e441c5995a22629846573c39f3 (refs/remotes/origin/master)
// Enabling Git LFS pull
// > git config core.sparsecheckout # timeout=10
// > git read-tree -mu HEAD # timeout=10
// > git checkout -f d0788d22622862e441c5995a22629846573c39f3 # timeout=120
// > git config --get remote.origin.url # timeout=10
// > git lfs pull origin # timeout=120
// Commit message: "2.10180.7389.21125_3"
// > git rev-list --no-walk d0788d22622862e441c5995a22629846573c39f3 # timeout=10
// gitCheckout (below) cannot handle sparse checkout and lfs at the moment - see https://issues.jenkins-ci.org/browse/JENKINS-43427 - see gitCheckoutAlt()
def gitCheckout(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
checkgitlfsinstall()
def reporootpath = checkouttoreporoot(gitURL)