From f02aa401e716ab04392ee3632258fcf0255a7052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sz=C3=A9pk=C3=BAti?= Date: Tue, 30 May 2023 19:33:09 +0200 Subject: [PATCH 1/3] Adjust the options of the parametrized repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Explicitly name the remote origin - Only fetch the branches specified in the refspec - Let Jenkins determine the name of the local branch automatically Signed-off-by: Bence Szépkúti --- vars/checkout_repo.groovy | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vars/checkout_repo.groovy b/vars/checkout_repo.groovy index 096495782..2f1eaf8be 100644 --- a/vars/checkout_repo.groovy +++ b/vars/checkout_repo.groovy @@ -38,15 +38,16 @@ def checkout_parametrized_repo(repo, branch) { scm: [ $class: 'GitSCM', userRemoteConfigs: [[ + name: 'origin', url: repo, refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/pull/*', credentialsId: env.GIT_CREDENTIALS_ID ]], branches: [[name: branch]], extensions: [ - [$class: 'CloneOption', timeout: 60], + [$class: 'CloneOption', timeout: 60, honorRefspec: true], [$class: 'SubmoduleOption', recursiveSubmodules: true], - [$class: 'LocalBranch', localBranch: branch], + [$class: 'LocalBranch', localBranch: '**'], ], ] ]) From 64d47b787354e72a6f29cb7a48653dbd72ce8603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sz=C3=A9pk=C3=BAti?= Date: Tue, 30 May 2023 19:29:53 +0200 Subject: [PATCH 2/3] Return scm map representing parametrized repo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of checking the repo out in the function, we do so in the caller. Signed-off-by: Bence Szépkúti --- vars/checkout_repo.groovy | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/vars/checkout_repo.groovy b/vars/checkout_repo.groovy index 2f1eaf8be..572b3d088 100644 --- a/vars/checkout_repo.groovy +++ b/vars/checkout_repo.groovy @@ -21,7 +21,7 @@ def checkout_repo() { if (env.TARGET_REPO == 'tls' && env.CHECKOUT_METHOD == 'scm') { checkout scm } else { - checkout_parametrized_repo(MBED_TLS_REPO, MBED_TLS_BRANCH) + checkout parametrized_repo(MBED_TLS_REPO, MBED_TLS_BRANCH) } } @@ -29,28 +29,26 @@ def checkout_mbed_os_example_repo(repo, branch) { if (env.TARGET_REPO == 'example' && env.CHECKOUT_METHOD == 'scm') { checkout scm } else { - checkout_parametrized_repo(repo, branch) + checkout parametrized_repo(repo, branch) } } -def checkout_parametrized_repo(repo, branch) { - checkout([ - scm: [ - $class: 'GitSCM', - userRemoteConfigs: [[ - name: 'origin', - url: repo, - refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/pull/*', - credentialsId: env.GIT_CREDENTIALS_ID - ]], - branches: [[name: branch]], - extensions: [ - [$class: 'CloneOption', timeout: 60, honorRefspec: true], - [$class: 'SubmoduleOption', recursiveSubmodules: true], - [$class: 'LocalBranch', localBranch: '**'], - ], - ] - ]) +Map parametrized_repo(String repo, String branch) { + return [ + $class: 'GitSCM', + userRemoteConfigs: [[ + name: 'origin', + url: repo, + refspec: '+refs/heads/*:refs/remotes/origin/* +refs/pull/*:refs/pull/*', + credentialsId: env.GIT_CREDENTIALS_ID + ]], + branches: [[name: branch]], + extensions: [ + [$class: 'CloneOption', timeout: 60, honorRefspec: true], + [$class: 'SubmoduleOption', recursiveSubmodules: true], + [$class: 'LocalBranch', localBranch: '**'], + ], + ] } def checkout_mbed_os() { From ceedadc1d3ef25bdf3ee2300dc15fcf1fd4f9476 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sz=C3=A9pk=C3=BAti?= Date: Tue, 16 May 2023 22:35:20 +0200 Subject: [PATCH 3/3] Chache git objects on Jenkins agents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should reduce network usage and speed up builds Signed-off-by: Bence Szépkúti --- vars/checkout_repo.groovy | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/vars/checkout_repo.groovy b/vars/checkout_repo.groovy index 572b3d088..290e34ae4 100644 --- a/vars/checkout_repo.groovy +++ b/vars/checkout_repo.groovy @@ -17,12 +17,29 @@ * This file is part of Mbed TLS (https://www.trustedfirmware.org/projects/mbed-tls/) */ +import hudson.plugins.git.GitSCM + def checkout_repo() { - if (env.TARGET_REPO == 'tls' && env.CHECKOUT_METHOD == 'scm') { - checkout scm - } else { - checkout parametrized_repo(MBED_TLS_REPO, MBED_TLS_BRANCH) + def git_scm = null + def cache = "$env.WORKSPACE/../../mbedtls-git-cache/mbedtls" + dir(cache) { + if (env.TARGET_REPO == 'tls' && env.CHECKOUT_METHOD == 'scm') { + git_scm = scm + } else { + git_scm = parametrized_repo(env.MBED_TLS_REPO, env.MBED_TLS_BRANCH) + } + checkout git_scm } + checkout([ + $class: 'GitSCM', + userRemoteConfigs: [[ + name: 'cache', + url: cache, + refspec: '+refs/remotes/origin/*:refs/remotes/cache/* +refs/pull/*:refs/pull/*' + ]] + git_scm.userRemoteConfigs, + branches: git_scm.branches, + extensions: git_scm.extensions + ]) } def checkout_mbed_os_example_repo(repo, branch) {