From 4942d1bc6bbf30c5a16c23cf5070d15ec0da0345 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Fri, 29 Mar 2019 08:44:12 +0000 Subject: [PATCH] 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: [