From a4f8b91cd2d0f397ad80f1e9a7c8afcf0811d82e Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:02:46 +0000 Subject: [PATCH 01/21] Patch to fetch all branches required to jenkins documentation when using localbranch Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 9dca6091..c20a4180 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -18,7 +18,7 @@ class GitLocalBranch extends Git implements Serializable { steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + userRemoteConfigs: steps.scm.userRemoteConfigs + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ]) } @@ -30,7 +30,7 @@ class GitLocalBranch extends Git implements Serializable { extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId] + userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ]) } From afa955298fcde0061b80b647c0dc70ee1a349dc6 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:17:58 +0000 Subject: [PATCH 02/21] Replace exactly with issue code to debug Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index c20a4180..e426fd7e 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,22 +15,32 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - steps.checkout transformGitSCM([ - branches: steps.scm.branches, - extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] - ]) + steps.checkout transformGitSCM(checkout([ + branches: scm.branches, + doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, + extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + userRemoteConfigs: [[ + credentialsId: scm.userRemoteConfigs[0].credentialsId, + name: 'origin', + refspec: '+refs/heads/*:refs/remotes/origin/*', + url: scm.userRemoteConfigs[0].url + ]], + ])) } @Override def checkoutRepository(String repository, String branch='master', String credentialsId) { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } steps.checkout transformGitSCM([ - branches: [[name: "*/${branch}"]], - extensions: steps.scm.extensions + - [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + - [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] + branches: branch, + doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, + extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + userRemoteConfigs: [[ + credentialsId: credentialsId, + name: 'origin', + refspec: '+refs/heads/*:refs/remotes/origin/*', + url: repository + ]], ]) } From 13243c401ab6486f6f01efa3d7fb7d48ff46fc38 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:37:06 +0000 Subject: [PATCH 03/21] Add steps.scm to correct previous commit bug Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index e426fd7e..622ec6cc 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -16,14 +16,14 @@ class GitLocalBranch extends Git implements Serializable { def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } steps.checkout transformGitSCM(checkout([ - branches: scm.branches, - doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, - extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + branches: steps.scm.branches, + doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, + extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], userRemoteConfigs: [[ - credentialsId: scm.userRemoteConfigs[0].credentialsId, + credentialsId: steps.scm.userRemoteConfigs[0].credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*', - url: scm.userRemoteConfigs[0].url + url: steps.scm.userRemoteConfigs[0].url ]], ])) } @@ -33,8 +33,8 @@ class GitLocalBranch extends Git implements Serializable { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } steps.checkout transformGitSCM([ branches: branch, - doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, - extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, + extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], userRemoteConfigs: [[ credentialsId: credentialsId, name: 'origin', From 75bc51bf9ebd547a46b0225332b7f0c788620831 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:48:49 +0000 Subject: [PATCH 04/21] Remove wrong checkout call added from copy paste Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 622ec6cc..3907fe5c 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,7 +15,7 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - steps.checkout transformGitSCM(checkout([ + steps.checkout transformGitSCM([ branches: steps.scm.branches, doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], @@ -25,7 +25,7 @@ class GitLocalBranch extends Git implements Serializable { refspec: '+refs/heads/*:refs/remotes/origin/*', url: steps.scm.userRemoteConfigs[0].url ]], - ])) + ]) } @Override From 3b697a51b8775df656b9eb2fbf2f41c469ac6a38 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:58:47 +0000 Subject: [PATCH 05/21] Revert "Remove wrong checkout call added from copy paste" This reverts commit 75bc51bf9ebd547a46b0225332b7f0c788620831. --- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 3907fe5c..622ec6cc 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,7 +15,7 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - steps.checkout transformGitSCM([ + steps.checkout transformGitSCM(checkout([ branches: steps.scm.branches, doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], @@ -25,7 +25,7 @@ class GitLocalBranch extends Git implements Serializable { refspec: '+refs/heads/*:refs/remotes/origin/*', url: steps.scm.userRemoteConfigs[0].url ]], - ]) + ])) } @Override From 00f518ab95a2da1b32abf698fd12cce3c84a3f79 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:58:58 +0000 Subject: [PATCH 06/21] Revert "Add steps.scm to correct previous commit bug" This reverts commit 13243c401ab6486f6f01efa3d7fb7d48ff46fc38. --- src/eu/indigo/scm/GitLocalBranch.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 622ec6cc..e426fd7e 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -16,14 +16,14 @@ class GitLocalBranch extends Git implements Serializable { def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } steps.checkout transformGitSCM(checkout([ - branches: steps.scm.branches, - doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, - extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + branches: scm.branches, + doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, + extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], userRemoteConfigs: [[ - credentialsId: steps.scm.userRemoteConfigs[0].credentialsId, + credentialsId: scm.userRemoteConfigs[0].credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*', - url: steps.scm.userRemoteConfigs[0].url + url: scm.userRemoteConfigs[0].url ]], ])) } @@ -33,8 +33,8 @@ class GitLocalBranch extends Git implements Serializable { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } steps.checkout transformGitSCM([ branches: branch, - doGenerateSubmoduleConfigurations: steps.scm.doGenerateSubmoduleConfigurations, - extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, + extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], userRemoteConfigs: [[ credentialsId: credentialsId, name: 'origin', From 025201299bc6ca420ce05563eaf056a434d3725f Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 12:59:04 +0000 Subject: [PATCH 07/21] Revert "Replace exactly with issue code to debug" This reverts commit afa955298fcde0061b80b647c0dc70ee1a349dc6. --- src/eu/indigo/scm/GitLocalBranch.groovy | 30 +++++++++---------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index e426fd7e..c20a4180 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,32 +15,22 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - steps.checkout transformGitSCM(checkout([ - branches: scm.branches, - doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, - extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[ - credentialsId: scm.userRemoteConfigs[0].credentialsId, - name: 'origin', - refspec: '+refs/heads/*:refs/remotes/origin/*', - url: scm.userRemoteConfigs[0].url - ]], - ])) + steps.checkout transformGitSCM([ + branches: steps.scm.branches, + extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], + userRemoteConfigs: steps.scm.userRemoteConfigs + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] + ]) } @Override def checkoutRepository(String repository, String branch='master', String credentialsId) { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } steps.checkout transformGitSCM([ - branches: branch, - doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations, - extensions: scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[ - credentialsId: credentialsId, - name: 'origin', - refspec: '+refs/heads/*:refs/remotes/origin/*', - url: repository - ]], + branches: [[name: "*/${branch}"]], + extensions: steps.scm.extensions + + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + + [$class: 'LocalBranch', localBranch: '**'], + userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ]) } From e5230799df60be9bcfee9638f976d36ea5ae8047 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 13:19:48 +0000 Subject: [PATCH 08/21] Correct bug in userRemoteConfigs Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index c20a4180..9840ed04 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -18,7 +18,7 @@ class GitLocalBranch extends Git implements Serializable { steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] + userRemoteConfigs: steps.scm.userRemoteConfigs + [[name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] ]) } @@ -30,7 +30,7 @@ class GitLocalBranch extends Git implements Serializable { extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] + userRemoteConfigs: steps.scm.userRemoteConfigs + [[url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] ]) } From d0b9658f4eb329938c6e30c4ccb16395c7c4b44a Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 13:22:12 +0000 Subject: [PATCH 09/21] Correct bug in userRemoteConfigs also for scm.Git Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 1ca76eef..dd644d86 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -35,7 +35,7 @@ class Git extends JenkinsDefinitions implements Serializable { steps.checkout transformGitSCM([ branches: [[name: "*/${branch}"]], extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId] + userRemoteConfigs: steps.scm.userRemoteConfigs + [[url: repository, credentialsId: credentialsId]] ]) } From 4dfe8fd87c76e6973cb2e403f14efc1c6d9010c4 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 13:32:24 +0000 Subject: [PATCH 10/21] Bug: correct userRemoteConfigs because operation was being applied to the array list and not the Map. With this only a single element list is expected Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 2 +- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index dd644d86..857d07b3 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -35,7 +35,7 @@ class Git extends JenkinsDefinitions implements Serializable { steps.checkout transformGitSCM([ branches: [[name: "*/${branch}"]], extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [[url: repository, credentialsId: credentialsId]] + userRemoteConfigs: [ steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId] ] ]) } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 9840ed04..b0abf1c5 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -18,7 +18,7 @@ class GitLocalBranch extends Git implements Serializable { steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [[name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] + userRemoteConfigs: [ steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] ]) } @@ -30,7 +30,7 @@ class GitLocalBranch extends Git implements Serializable { extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: steps.scm.userRemoteConfigs + [[url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] + userRemoteConfigs: [ steps.scm.userRemoteConfigs[0] + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] ]) } From f04d3ba535120dbcc0d41046de52f0b5cef779d7 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 13:48:34 +0000 Subject: [PATCH 11/21] Debug userRemoteConfigs Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index b0abf1c5..6604bfe8 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,10 +15,11 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } + userRemoteConfigs = steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [ steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] + userRemoteConfigs: [ userRemoteConfigs ] ]) } From 6f5b58f8b9e253a9a3636d6060ef5398ef6ef38b Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 14:00:56 +0000 Subject: [PATCH 12/21] Force type cast to Map for userRemoteConfigs Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 6604bfe8..bb9953f7 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,11 +15,10 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - userRemoteConfigs = steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [ userRemoteConfigs ] + userRemoteConfigs: [ (Map)steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] ]) } From a2946b0f865d14df2196ee723a5124c1c7f61a74 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 14:11:42 +0000 Subject: [PATCH 13/21] Need to implement as operator to manage userRemoteConfigs dinamically. Because of that for now is only possible to define the array as new, using default values when required. Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 2 +- src/eu/indigo/scm/GitLocalBranch.groovy | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 857d07b3..6a7827a1 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -35,7 +35,7 @@ class Git extends JenkinsDefinitions implements Serializable { steps.checkout transformGitSCM([ branches: [[name: "*/${branch}"]], extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'], - userRemoteConfigs: [ steps.scm.userRemoteConfigs + [url: repository, credentialsId: credentialsId] ] + userRemoteConfigs: [[url: repository, credentialsId: credentialsId]] ]) } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index bb9953f7..30aa50e7 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -18,7 +18,7 @@ class GitLocalBranch extends Git implements Serializable { steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [ (Map)steps.scm.userRemoteConfigs[0] + [name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] + userRemoteConfigs: [[credentialsId: scm.userRemoteConfigs[0].credentialsId, url: scm.userRemoteConfigs[0].url, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] ]) } @@ -30,7 +30,7 @@ class GitLocalBranch extends Git implements Serializable { extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [ steps.scm.userRemoteConfigs[0] + [url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*'] ] + userRemoteConfigs: [[url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] ]) } From 1e0df9a4b7af04efb08e90e6c764c8c11b49bafc Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 14:14:23 +0000 Subject: [PATCH 14/21] Need to implement as operator to manage userRemoteConfigs dinamically. Because of that for now is only possible to define the array as new, using default values when required. Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/GitLocalBranch.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 30aa50e7..1dbaf13c 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -18,7 +18,7 @@ class GitLocalBranch extends Git implements Serializable { steps.checkout transformGitSCM([ branches: steps.scm.branches, extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[credentialsId: scm.userRemoteConfigs[0].credentialsId, url: scm.userRemoteConfigs[0].url, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] + userRemoteConfigs: [[credentialsId: steps.scm.userRemoteConfigs[0].credentialsId, url: steps.scm.userRemoteConfigs[0].url, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] ]) } From 80d6b5a5518cf2f238a05188098b18870216d5e7 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Fri, 4 Dec 2020 21:33:17 +0000 Subject: [PATCH 15/21] Code improvement, but not yet the best composition to support GitSCM extensions Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 30 ++++++++++++++++++++++--- src/eu/indigo/scm/GitLocalBranch.groovy | 12 +++++----- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 6a7827a1..7066b6ed 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -18,6 +18,7 @@ class Git extends JenkinsDefinitions implements Serializable { */ Git(steps) { super(steps) + this.remoteConfigs = [] } @NonCPS @@ -25,6 +26,28 @@ class Git extends JenkinsDefinitions implements Serializable { [ $class: 'GitSCM' ] + config } + @NonCPS + protected def userRemoteConfigs(url, name, refspec, credentialsId) { + remoteConfigs += [[url: url, name: name, refspec: refspec, credentialsId: credentialsId]] + } + + @NonCPS + protected def branches(names) { + names.collect { name -> + [name: name] + } + } + + @NonCPS + protected def relativeTargetDirectory(relativeTargetDir) { + [$class: 'RelativeTargetDirectory', relativeTargetDir: relativeTargetDir] + } + + @NonCPS + protected def localBranch(localBranch) { + [$class: 'LocalBranch', localBranch: localBranch] + } + def checkoutRepository() { if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } steps.checkout steps.scm @@ -32,10 +55,11 @@ class Git extends JenkinsDefinitions implements Serializable { def checkoutRepository(String repository, String branch='master', String credentialsId) { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } + userRemoteConfigs(repository, '', '', credentialsId) steps.checkout transformGitSCM([ - branches: [[name: "*/${branch}"]], - extensions: steps.scm.extensions + [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'], - userRemoteConfigs: [[url: repository, credentialsId: credentialsId]] + branches: branches(["*/${branch}"]), + extensions: steps.scm.extensions + relativeTargetDirectory('.'), + userRemoteConfigs: remoteConfigs ]) } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index 1dbaf13c..ee869a6e 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -17,8 +17,8 @@ class GitLocalBranch extends Git implements Serializable { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } steps.checkout transformGitSCM([ branches: steps.scm.branches, - extensions: steps.scm.extensions + [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[credentialsId: steps.scm.userRemoteConfigs[0].credentialsId, url: steps.scm.userRemoteConfigs[0].url, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] + extensions: steps.scm.extensions + localBranch('**'), + userRemoteConfigs: userRemoteConfigs(steps.scm.userRemoteConfigs[0].url, 'origin', '+refs/heads/*:refs/remotes/origin/*', steps.scm.userRemoteConfigs[0].credentialsId) ]) } @@ -26,11 +26,9 @@ class GitLocalBranch extends Git implements Serializable { def checkoutRepository(String repository, String branch='master', String credentialsId) { if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } steps.checkout transformGitSCM([ - branches: [[name: "*/${branch}"]], - extensions: steps.scm.extensions + - [$class: 'RelativeTargetDirectory', relativeTargetDir: '.'] + - [$class: 'LocalBranch', localBranch: '**'], - userRemoteConfigs: [[url: repository, credentialsId: credentialsId, name: 'origin', refspec: '+refs/heads/*:refs/remotes/origin/*']] + branches: branches(["*/${branch}"]), + extensions: steps.scm.extensions + relativeTargetDirectory('.') + localBranch('**'), + userRemoteConfigs: userRemoteConfigs(repository, 'origin', '+refs/heads/*:refs/remotes/origin/*', credentialsId) ]) } From f481e6a8dc28a2bd93e894bb11929f3404050086 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Mon, 7 Dec 2020 22:49:02 +0000 Subject: [PATCH 16/21] Debugging remoteConfigs Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 1 + 1 file changed, 1 insertion(+) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 7066b6ed..1488b122 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -11,6 +11,7 @@ class Git extends JenkinsDefinitions implements Serializable { private static final long serialVersionUID = 0L + def remoteConfigs /** * Define constructor to import definitions from Jenkins context From 183f32fdd6718fe1f87e054b7d27b232bd59cbd0 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Tue, 8 Dec 2020 00:53:17 +0000 Subject: [PATCH 17/21] Apply adapter pattern and optimize code Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 63 +++++++++++++++++++++---- src/eu/indigo/scm/GitLocalBranch.groovy | 38 ++++++++++----- 2 files changed, 79 insertions(+), 22 deletions(-) diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 1488b122..89ef7876 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -12,6 +12,9 @@ class Git extends JenkinsDefinitions implements Serializable { private static final long serialVersionUID = 0L def remoteConfigs + def extensions + def branches + protected def gitObject /** * Define constructor to import definitions from Jenkins context @@ -20,6 +23,32 @@ class Git extends JenkinsDefinitions implements Serializable { Git(steps) { super(steps) this.remoteConfigs = [] + this.extensions = steps.scm.extensions + this.branches = steps.scm.branches + } + + Git(steps, gitObject) { + this.Git(steps) + this.gitObject = gitObject + } + + protected def checkoutScm() { + gitObject ? gitObject.checkoutRepository() : checkoutRepository() + } + + protected def checkoutScm( + String repository, + String credentialsId, + String name, + String refspec, + String branch, + String targetDirectory) { + if (gitObject) { + gitObject.checkoutRepository(repository, credentialsId, name, refspec, branch, targetDirectory) + } + else { + checkoutRepository(repository, credentialsId, name, refspec, branch, targetDirectory) + } } @NonCPS @@ -34,7 +63,7 @@ class Git extends JenkinsDefinitions implements Serializable { @NonCPS protected def branches(names) { - names.collect { name -> + branches = names.collect { name -> [name: name] } } @@ -49,19 +78,33 @@ class Git extends JenkinsDefinitions implements Serializable { [$class: 'LocalBranch', localBranch: localBranch] } - def checkoutRepository() { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } - steps.checkout steps.scm + @NonCPS + protected def extensionsLoader(extension) { + extensions += extension } - def checkoutRepository(String repository, String branch='master', String credentialsId) { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } - userRemoteConfigs(repository, '', '', credentialsId) + def checkoutRepository() { + if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } + if (remoteConfigs == []) { remoteConfigs = steps.scm.userRemoteConfigs } steps.checkout transformGitSCM([ - branches: branches(["*/${branch}"]), - extensions: steps.scm.extensions + relativeTargetDirectory('.'), - userRemoteConfigs: remoteConfigs + branches: branches, + extensions: extensions, + userRemoteConfigs: remoteConfigs, ]) } + def checkoutRepository( + String repository, + String credentialsId, + String name='', + String refspec='', + String branch='master', + String targetDirectory='.') { + if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $targetDirectory) **" } + userRemoteConfigs(repository, name, refspec, credentialsId) + branches(["*/${branch}"]) + extensionsLoader(relativeTargetDirectory(targetDirectory)) + checkoutRepository() + } + } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index ee869a6e..d4b4a1c4 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -15,21 +15,35 @@ class GitLocalBranch extends Git implements Serializable { @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } - steps.checkout transformGitSCM([ - branches: steps.scm.branches, - extensions: steps.scm.extensions + localBranch('**'), - userRemoteConfigs: userRemoteConfigs(steps.scm.userRemoteConfigs[0].url, 'origin', '+refs/heads/*:refs/remotes/origin/*', steps.scm.userRemoteConfigs[0].credentialsId) - ]) + userRemoteConfigs(steps.scm.userRemoteConfigs[0].url, 'origin', '+refs/heads/*:refs/remotes/origin/*', steps.scm.userRemoteConfigs[0].credentialsId) + extensionsLoader(localBranch('**')) + checkoutScm() } @Override - def checkoutRepository(String repository, String branch='master', String credentialsId) { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $branch, $credentialsId) **" } - steps.checkout transformGitSCM([ - branches: branches(["*/${branch}"]), - extensions: steps.scm.extensions + relativeTargetDirectory('.') + localBranch('**'), - userRemoteConfigs: userRemoteConfigs(repository, 'origin', '+refs/heads/*:refs/remotes/origin/*', credentialsId) - ]) + def checkoutRepository( + String repository, + String credentialsId, + String name='', + String refspec='', + String branch='master', + String targetDirectory='.') { + if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $targetDirectory) **" } + extensionsLoader(localBranch('**')) + checkoutScm(repository, credentialsId, name, refspec, branch, targetDirectory) + } + + def checkoutRepository( + String repository, + String credentialsId, + String name='', + String refspec='', + String branch='master', + String targetDirectory='.', + String localBranchName='**') { + if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $localBranchName, $targetDirectory) **" } + extensionsLoader(localBranch(localBranchName)) + checkoutScm(repository, credentialsId, name, refspec, branch, targetDirectory) } } From 94ff435511c686e57a35a8176e2b91bfba55e526 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Thu, 10 Dec 2020 00:35:27 +0000 Subject: [PATCH 18/21] pipelineConfig: optimize arguments and correct default value for localBranch Signed-off-by: Samuel Bernardo --- vars/pipelineConfig.groovy | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/vars/pipelineConfig.groovy b/vars/pipelineConfig.groovy index 45c561f0..d704955f 100644 --- a/vars/pipelineConfig.groovy +++ b/vars/pipelineConfig.groovy @@ -9,21 +9,10 @@ import eu.indigo.Tox import eu.indigo.scm.Git import eu.indigo.scm.GitLocalBranch -def call( - Map configs=[ - configFile: './.sqa/config.yml', - baseRepository: null, - baseBranch: null, - credentialsId: null, - validatorDockerImage: 'eoscsynergy/jpl-validator:1.1.0', - scmConfigs: [ - localBranch: false, - ], - ] - ) { +def call(Map configs) { Map scmConfigsDefault = [ - localBranch: false + localBranch: '', ] Map scmConfigs = configs?.scmConfigs ? scmConfigsDefault + configs?.scmConfigs : scmConfigsDefault From 7725ad28c3da0ec04a6e4d302ae90767e73f5e97 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Thu, 10 Dec 2020 02:40:13 +0000 Subject: [PATCH 19/21] Set adapter pattern for scm classes Signed-off-by: Samuel Bernardo --- src/eu/indigo/scm/Git.groovy | 30 +++++++++++------------- src/eu/indigo/scm/GitLocalBranch.groovy | 22 ++++++------------ src/eu/indigo/scm/GitProperties.groovy | 31 +++++++++++++++++++++++++ vars/pipelineConfig.groovy | 11 +++++---- 4 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 src/eu/indigo/scm/GitProperties.groovy diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index 89ef7876..dd7f4952 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -11,24 +11,20 @@ class Git extends JenkinsDefinitions implements Serializable { private static final long serialVersionUID = 0L - def remoteConfigs - def extensions - def branches - protected def gitObject + protected GitProperties properties + protected Git gitObject /** * Define constructor to import definitions from Jenkins context * @see https://www.jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps */ - Git(steps) { + Git(steps, properties) { super(steps) - this.remoteConfigs = [] - this.extensions = steps.scm.extensions - this.branches = steps.scm.branches + this.properties = properties } - Git(steps, gitObject) { - this.Git(steps) + Git(steps, properties, gitObject) { + this.Git(steps, properties) this.gitObject = gitObject } @@ -58,12 +54,12 @@ class Git extends JenkinsDefinitions implements Serializable { @NonCPS protected def userRemoteConfigs(url, name, refspec, credentialsId) { - remoteConfigs += [[url: url, name: name, refspec: refspec, credentialsId: credentialsId]] + properties.remoteConfigs += [[url: url, name: name, refspec: refspec, credentialsId: credentialsId]] } @NonCPS protected def branches(names) { - branches = names.collect { name -> + properties.branches = names.collect { name -> [name: name] } } @@ -80,16 +76,16 @@ class Git extends JenkinsDefinitions implements Serializable { @NonCPS protected def extensionsLoader(extension) { - extensions += extension + properties.extensions += extension } def checkoutRepository() { if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } - if (remoteConfigs == []) { remoteConfigs = steps.scm.userRemoteConfigs } + if (properties.remoteConfigs == []) { properties.remoteConfigs = steps.scm.userRemoteConfigs } steps.checkout transformGitSCM([ - branches: branches, - extensions: extensions, - userRemoteConfigs: remoteConfigs, + branches: properties.branches, + extensions: properties.extensions, + userRemoteConfigs: properties.remoteConfigs, ]) } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index d4b4a1c4..bbfd9c2f 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -12,11 +12,16 @@ class GitLocalBranch extends Git implements Serializable { private static final long serialVersionUID = 0L + GitLocalBranch(steps, properties, gitObject, localBranch) { + super(steps, properties, gitObject) + super.properties.localBranch = localBranch + } + @Override def checkoutRepository() { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository() **" } userRemoteConfigs(steps.scm.userRemoteConfigs[0].url, 'origin', '+refs/heads/*:refs/remotes/origin/*', steps.scm.userRemoteConfigs[0].credentialsId) - extensionsLoader(localBranch('**')) + extensionsLoader(localBranch(properties.localBranch)) checkoutScm() } @@ -29,20 +34,7 @@ class GitLocalBranch extends Git implements Serializable { String branch='master', String targetDirectory='.') { if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $targetDirectory) **" } - extensionsLoader(localBranch('**')) - checkoutScm(repository, credentialsId, name, refspec, branch, targetDirectory) - } - - def checkoutRepository( - String repository, - String credentialsId, - String name='', - String refspec='', - String branch='master', - String targetDirectory='.', - String localBranchName='**') { - if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $localBranchName, $targetDirectory) **" } - extensionsLoader(localBranch(localBranchName)) + extensionsLoader(localBranch(properties.localBranch)) checkoutScm(repository, credentialsId, name, refspec, branch, targetDirectory) } diff --git a/src/eu/indigo/scm/GitProperties.groovy b/src/eu/indigo/scm/GitProperties.groovy new file mode 100644 index 00000000..9b1ed062 --- /dev/null +++ b/src/eu/indigo/scm/GitProperties.groovy @@ -0,0 +1,31 @@ +package eu.indigo.scm + +import eu.indigo.JenkinsDefinitions + +/** + * Jenkins workflow SCM step + * @see: https://www.jenkins.io/doc/pipeline/steps/workflow-scm-step/ + */ +@groovy.transform.InheritConstructors +class GitProperties extends JenkinsDefinitions implements Serializable { + + private static final long serialVersionUID = 0L + + def remoteConfigs + def extensions + def branches + def localBranch + + /** + * Define constructor to import definitions from Jenkins context + * @see https://www.jenkins.io/doc/book/pipeline/shared-libraries/#accessing-steps + */ + GitProperties(steps) { + super(steps) + this.remoteConfigs = [] + this.extensions = steps.scm.extensions + this.branches = steps.scm.branches + this.localBranch = '' + } + +} \ No newline at end of file diff --git a/vars/pipelineConfig.groovy b/vars/pipelineConfig.groovy index d704955f..cb05cac6 100644 --- a/vars/pipelineConfig.groovy +++ b/vars/pipelineConfig.groovy @@ -7,12 +7,13 @@ import eu.indigo.compose.ComposeFactoryBuilder import eu.indigo.compose.DockerCompose import eu.indigo.Tox import eu.indigo.scm.Git +import eu.indigo.scm.GitProperties import eu.indigo.scm.GitLocalBranch def call(Map configs) { Map scmConfigsDefault = [ - localBranch: '', + localBranch: null, ] Map scmConfigs = configs?.scmConfigs ? scmConfigsDefault + configs?.scmConfigs : scmConfigsDefault @@ -38,12 +39,12 @@ def call(Map configs) { } scmCheckout.resolveStrategy = Closure.DELEGATE_FIRST + props = new GitProperties(this) + gitObj = new Git(this, props) if (configs?.scmConfigs?.localBranch) { - scmCheckout.delegate = new GitLocalBranch(this) - } - else { - scmCheckout.delegate = new Git(this) + scmCheckout.delegate = new GitLocalBranch(this, props, gitObj, configs.scmConfigs.localBranch) } + scmCheckout.delegate = gitObj scmCheckout() def yaml = readYaml file: configs.configFile From 03bc6bbd29806073ea15337508118533eadc6615 Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Thu, 10 Dec 2020 03:45:35 +0000 Subject: [PATCH 20/21] Define checkoutRepository arguments as a Map. Replace DockerCompose scm checkout with new scm package classes (missing code for some new classes). Signed-off-by: Samuel Bernardo --- src/eu/indigo/compose/DockerCompose.groovy | 14 +++++----- src/eu/indigo/scm/Git.groovy | 30 ++++++++++++++-------- src/eu/indigo/scm/GitLocalBranch.groovy | 13 +++------- vars/pipelineConfig.groovy | 2 +- 4 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/eu/indigo/compose/DockerCompose.groovy b/src/eu/indigo/compose/DockerCompose.groovy index 7f940a36..4b96832b 100644 --- a/src/eu/indigo/compose/DockerCompose.groovy +++ b/src/eu/indigo/compose/DockerCompose.groovy @@ -316,13 +316,13 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { steps.stage("Environment Setup") { // Checkout repositories to workspace with defined repository name projectConfig.config.project_repos?.each { repo_name, repo_confs -> - steps.checkout scm: [$class: 'GitSCM', userRemoteConfigs: [[url: repo_confs.repo, credentialsId: repo_confs.credentials_id]], - branches: [[name: repo_confs.branch]], - extensions: [[$class: 'CleanCheckout', deleteUntrackedNestedRepositories: true], - [$class: 'GitLFSPull'], - [$class: 'RelativeTargetDirectory', relativeTargetDir: repo_name], - [$class: 'ScmName', name: repo_name]] ], - changelog: false, poll: false + props = new GitProperties(steps) + gitObj = new Git(steps, props) + gitObj = new GitScmName(steps, props, gitObj, repo_name) + gitObj = new GitCleanCheckout(steps, props, gitObj, repo_confs.deleteUntrackedNestedRepositories) + repo_confs.gitLfsPull ? gitObj = new GitLFSPull(steps, props, gitObj) + gitObj = new GeneralOptions(steps, props, gitObj, repo_confs.changelog, repo_confs.poll) + gitObj.checkoutRepository(baseRepository: repo_confs.repo, credentialsId: repo_confs.credentials_id, baseBranch: repo_confs.branch, relativeTargetDir: repo_name) } } diff --git a/src/eu/indigo/scm/Git.groovy b/src/eu/indigo/scm/Git.groovy index dd7f4952..95ce24a9 100644 --- a/src/eu/indigo/scm/Git.groovy +++ b/src/eu/indigo/scm/Git.groovy @@ -79,6 +79,19 @@ class Git extends JenkinsDefinitions implements Serializable { properties.extensions += extension } + def setDefaults(settings) { + Map defaultSettings = [ + baseRepository: null, + credentialsId: null, + baseBranch: 'master', + relativeTargetDir: '.', + remoteName: '', + refspec: '', + ] + settings ? defaultSettings + settings : + defaultSettings + } + def checkoutRepository() { if (_DEBUG_) { steps.echo "** Git.checkoutRepository() **" } if (properties.remoteConfigs == []) { properties.remoteConfigs = steps.scm.userRemoteConfigs } @@ -89,17 +102,12 @@ class Git extends JenkinsDefinitions implements Serializable { ]) } - def checkoutRepository( - String repository, - String credentialsId, - String name='', - String refspec='', - String branch='master', - String targetDirectory='.') { - if (_DEBUG_) { steps.echo "** Git.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $targetDirectory) **" } - userRemoteConfigs(repository, name, refspec, credentialsId) - branches(["*/${branch}"]) - extensionsLoader(relativeTargetDirectory(targetDirectory)) + def checkoutRepository(Map settings) { + settings = setDefaults(settings) + if (_DEBUG_) { steps.echo "** Git.checkoutRepository(${settings.baseRepository}, ${settings.credentialsId}, ${settings.baseBranch}, ${settings.remoteName}, ${settings.refspec}, ${settings.relativeTargetDir}) **" } + userRemoteConfigs(settings.baseRepository, settings.remoteName, settings.refspec, settings.credentialsId) + branches(["*/${settings.baseBranch}"]) + extensionsLoader(relativeTargetDirectory(settings.relativeTargetDir)) checkoutRepository() } diff --git a/src/eu/indigo/scm/GitLocalBranch.groovy b/src/eu/indigo/scm/GitLocalBranch.groovy index bbfd9c2f..8621eee6 100644 --- a/src/eu/indigo/scm/GitLocalBranch.groovy +++ b/src/eu/indigo/scm/GitLocalBranch.groovy @@ -26,16 +26,11 @@ class GitLocalBranch extends Git implements Serializable { } @Override - def checkoutRepository( - String repository, - String credentialsId, - String name='', - String refspec='', - String branch='master', - String targetDirectory='.') { - if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository($repository, $credentialsId, $name, $refspec, $branch, $targetDirectory) **" } + def checkoutRepository(Map settings) { + settings = setDefaults(settings) + if (_DEBUG_) { steps.echo "** GitLocalBranch.checkoutRepository(${settings.baseRepository}, ${settings.credentialsId}, ${settings.baseBranch}, ${settings.remoteName}, ${settings.refspec}, ${settings.relativeTargetDir}) **" } extensionsLoader(localBranch(properties.localBranch)) - checkoutScm(repository, credentialsId, name, refspec, branch, targetDirectory) + checkoutScm(baseRepository: settings.baseRepository, credentialsId: settings.credentialsId, baseBranch: settings.baseBranch, relativeTargetDir: settings.relativeTargetDir, remoteName: settings.remoteName, refspec: settings.refspec) } } diff --git a/vars/pipelineConfig.groovy b/vars/pipelineConfig.groovy index cb05cac6..3eb451bc 100644 --- a/vars/pipelineConfig.groovy +++ b/vars/pipelineConfig.groovy @@ -31,7 +31,7 @@ def call(Map configs) { def scmCheckout = { -> if (configs?.baseRepository) { - checkoutRepository(configs?.baseRepository, configs?.baseBranch, configs?.credentialsId) + checkoutRepository(baseRepository: configs?.baseRepository, credentialsId: configs?.credentialsId, baseBranch: configs?.baseBranch) } else { checkoutRepository() From f7a46fea0ec6937bca22f97b91257fe91ff514fd Mon Sep 17 00:00:00 2001 From: Samuel Bernardo Date: Thu, 10 Dec 2020 03:52:27 +0000 Subject: [PATCH 21/21] Add all classes from package scm in DockerCompose Signed-off-by: Samuel Bernardo --- src/eu/indigo/compose/DockerCompose.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/eu/indigo/compose/DockerCompose.groovy b/src/eu/indigo/compose/DockerCompose.groovy index 4b96832b..04dacc0f 100644 --- a/src/eu/indigo/compose/DockerCompose.groovy +++ b/src/eu/indigo/compose/DockerCompose.groovy @@ -3,6 +3,7 @@ package eu.indigo.compose import eu.indigo.JenkinsDefinitions import eu.indigo.compose.ProjectConfiguration import eu.indigo.Tox +import eu.indigo.scm.* /** * Definitions for Docker Compose integration in Jenkins @@ -332,7 +333,7 @@ class DockerCompose extends JenkinsDefinitions implements Serializable { withCredentialsClosure(credentials) { // Deploy the environment services using docker-compose composeUp(composeFile: projectConfig.config.deploy_template, workdir: workspace, forceBuild: steps.env.JPL_DOCKERFORCEBUILD) - + if (_DEBUG_) { steps.sh 'echo "after loading credentials:\n$(env)"' } projectConfig.stagesList.each { stageMap ->