From a756df369aae75957a999570992da95b59335fd1 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:44:12 +0000 Subject: [PATCH 1/5] Always create a repo_root copy of a repo when necessary - in order to speed up jobs --- versioncontrol/git.groovy | 51 +++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index ba4d96b..a474b6e 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -29,15 +29,50 @@ def guessreporoot(componentURL) { return reporoot } -def gitCheckout(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList sparseitemlist = new ArrayList()) { - reporootenv = env.REPO_ROOT - if (reporootenv != null && repoRootSuffix != "") { - reporootpath = "${reporootenv.trim()}/${repoRootSuffix}" - echo "Using release repo: ${reporootpath}" - } else { - reporootpath = "" +def String uniquereporootname(String gitURL) { + def uniquename = gitURL.replaceAll("[^A-Za-z0-9]", "_") + echo "Unique reporoot name for URL: ${gitURL} is: ${uniquename}" + return uniquename +} + +// The REPO_ROOT is a folder where a cache of git checkouts can be kept - each subfolder name is unique to a particular git repo +def String checkouttoreporoot(String gitURL) { + def String reporootsubfolder + def String reporootenv = env.REPO_ROOT + if (!reporootenv) { + reporootsubfolder = "" echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave" - } + } else { + def reporootname = uniquereporootname(gitURL) + def reporootsubfolder = "${reporootenv}/${reporootname}" + + if (!fileExists(reporootsubfolder)) { + echo "Checking out ${gitURL} to ${reporootname}" + checkout([ + $class: 'GitSCM', + userRemoteConfigs: [ + [url: gitURL] + ], + branches: [ + [name: 'origin/master'] + ], + doGenerateSubmoduleConfigurations: false, + extensions: [ + [$class: 'GitLFSPull'], + [$class: 'CleanBeforeCheckout'], + [$class: 'CheckoutOption', timeout: 180], + [$class: 'RelativeTargetDirectory', relativeTargetDir: reporootsubfolder], + ], + submoduleCfg: [], + ]) + } else { + echo "Found ${gitURL} checked out at ${reporootname}" + } + return reporootsubfolder +} + +def gitCheckout(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList sparseitemlist = new ArrayList()) { + def reporootpath = checkouttoreporoot(gitURL) checkout([ $class: 'GitSCM', userRemoteConfigs: [ From df087201a3f9bb54c2b65561f4c95fc21be1c344 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:48:35 +0000 Subject: [PATCH 2/5] Always create a repo_root copy of a repo when necessary - in order to speed up jobs --- versioncontrol/git.groovy | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index a474b6e..bd1b15e 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -19,16 +19,6 @@ def SparseCheckoutPaths sparsecheckoutconfig(ArrayList paths) { return new SparseCheckoutPaths(sparsecheckoutpaths) } -def guessreporoot(componentURL) { - if (!env.REPO_ROOT || env.REPO_ROOT.size() == 0) { - return '' - } - def guess = componentURL.replaceFirst(/.*\/(.*).git/, '$1') - def reporoot = "${REPO_ROOT}/${guess}" - echo "Guessing reporoot is: ${reporoot}" - return reporoot -} - def String uniquereporootname(String gitURL) { def uniquename = gitURL.replaceAll("[^A-Za-z0-9]", "_") echo "Unique reporoot name for URL: ${gitURL} is: ${uniquename}" @@ -68,6 +58,7 @@ def String checkouttoreporoot(String gitURL) { } else { echo "Found ${gitURL} checked out at ${reporootname}" } + } return reporootsubfolder } From 9dd09e4444eabe13100dec7a3dbca9b5825b5f20 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:49:54 +0000 Subject: [PATCH 3/5] Always create a repo_root copy of a repo when necessary - in order to speed up jobs --- versioncontrol/git.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index bd1b15e..ea3501c 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -34,7 +34,7 @@ def String checkouttoreporoot(String gitURL) { echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave" } else { def reporootname = uniquereporootname(gitURL) - def reporootsubfolder = "${reporootenv}/${reporootname}" + reporootsubfolder = "${reporootenv}/${reporootname}" if (!fileExists(reporootsubfolder)) { echo "Checking out ${gitURL} to ${reporootname}" From d1e8531b5ad42b0997fc53036a555e9c25c961fa Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:52:55 +0000 Subject: [PATCH 4/5] Always create a repo_root copy of a repo when necessary - in order to speed up jobs --- versioncontrol/git.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index ea3501c..432316f 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -34,10 +34,10 @@ def String checkouttoreporoot(String gitURL) { echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave" } else { def reporootname = uniquereporootname(gitURL) - reporootsubfolder = "${reporootenv}/${reporootname}" + reporootsubfolder = "${reporootenv}/${reporootsubfolder}" if (!fileExists(reporootsubfolder)) { - echo "Checking out ${gitURL} to ${reporootname}" + echo "Checking out ${gitURL} to ${reporootsubfolder}" checkout([ $class: 'GitSCM', userRemoteConfigs: [ @@ -56,7 +56,7 @@ def String checkouttoreporoot(String gitURL) { submoduleCfg: [], ]) } else { - echo "Found ${gitURL} checked out at ${reporootname}" + echo "Found ${gitURL} checked out at ${reporootsubfolder}" } } return reporootsubfolder From add368c009a6f99a15c7bf6d2de25af96be5600d Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:56:01 +0000 Subject: [PATCH 5/5] Always create a repo_root copy of a repo when necessary - in order to speed up jobs --- versioncontrol/git.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index 432316f..5599dc6 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -34,7 +34,7 @@ def String checkouttoreporoot(String gitURL) { echo "To improve Git performance: Define the REPO_ROOT enviroment to a path where a cache of git repositories can be placed on this slave" } else { def reporootname = uniquereporootname(gitURL) - reporootsubfolder = "${reporootenv}/${reporootsubfolder}" + reporootsubfolder = "${reporootenv}/${reporootname}" if (!fileExists(reporootsubfolder)) { echo "Checking out ${gitURL} to ${reporootsubfolder}"