From 058c6c0d9ad7de7b035af03ed94146db12454404 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Fri, 28 Sep 2018 15:32:58 +0200 Subject: [PATCH 1/6] Condence common code for cm scenario --- src/com/sap/piper/cm/StepHelpers.groovy | 37 +++++++++++++++++++++++++ vars/transportRequestRelease.groovy | 27 ++---------------- vars/transportRequestUploadFile.groovy | 27 ++---------------- 3 files changed, 41 insertions(+), 50 deletions(-) create mode 100644 src/com/sap/piper/cm/StepHelpers.groovy diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy new file mode 100644 index 000000000..bec9030ea --- /dev/null +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -0,0 +1,37 @@ +package com.sap.piper.cm; + +import com.cloudbees.groovy.cps.NonCPS + +public class StepHelpers { + + @NonCPS + public static def getTransportRequestId(ChangeManagement cm, def step, Map configuration) { + + def transportRequestId = configuration.transportRequestId + + if(transportRequestId?.trim()) { + + step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters." + + } else { + + step.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + + " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + + try { + transportRequestId = cm.getTransportRequestId( + configuration.changeManagement.git.from, + configuration.changeManagement.git.to, + configuration.changeManagement.transportRequestLabel, + configuration.changeManagement.git.format + ) + + step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" + + } catch(ChangeManagementException ex) { + step.echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}." + } + } + return transportRequestId + } +} diff --git a/vars/transportRequestRelease.groovy b/vars/transportRequestRelease.groovy index e5ecbcd9f..77fe9ccb9 100644 --- a/vars/transportRequestRelease.groovy +++ b/vars/transportRequestRelease.groovy @@ -9,6 +9,7 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException +import static com.sap.piper.cm.StepHelpers.getTransportRequestId @Field def STEP_NAME = 'transportRequestRelease' @@ -48,31 +49,7 @@ def call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME], configuration) - def transportRequestId = configuration.transportRequestId - - if(transportRequestId?.trim()) { - - echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters." - - } else { - - echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - " Searching for pattern '${configuration.gitTransportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - transportRequestId = cm.getTransportRequestId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.transportRequestLabel, - configuration.changeManagement.git.format - ) - - echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" - - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}." - } - } + def transportRequestId = getTransportRequestId(cm, this, configuration) def changeDocumentId = configuration.changeDocumentId diff --git a/vars/transportRequestUploadFile.groovy b/vars/transportRequestUploadFile.groovy index 98d388667..4507b7e9d 100644 --- a/vars/transportRequestUploadFile.groovy +++ b/vars/transportRequestUploadFile.groovy @@ -9,6 +9,7 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException +import static com.sap.piper.cm.StepHelpers.getTransportRequestId @Field def STEP_NAME = 'transportRequestUploadFile' @@ -80,31 +81,7 @@ def call(parameters = [:]) { } } - def transportRequestId = configuration.transportRequestId - - if(transportRequestId?.trim()) { - - echo "[INFO] Transport request id '${transportRequestId}' retrieved from parameters." - - } else { - - echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - transportRequestId = cm.getTransportRequestId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.transportRequestLabel, - configuration.changeManagement.git.format - ) - - echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" - - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve transportRequestId from commit history: ${ex.getMessage()}." - } - } + def transportRequestId = getTransportRequestId(cm, this, configuration) configuration = configHelper .mixin([changeDocumentId: changeDocumentId?.trim() ?: null, From 54ecc7d755efe31da12976e7b56c4bb790af76a2 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Fri, 28 Sep 2018 15:54:20 +0200 Subject: [PATCH 2/6] condence common code for getting change document id --- src/com/sap/piper/cm/StepHelpers.groovy | 30 +++++++++++++++++++++++++ vars/checkChangeInDevelopment.groovy | 28 +++-------------------- vars/transportRequestCreate.groovy | 27 ++-------------------- vars/transportRequestRelease.groovy | 28 ++--------------------- vars/transportRequestUploadFile.groovy | 28 ++--------------------- 5 files changed, 39 insertions(+), 102 deletions(-) diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index bec9030ea..15c45ebfc 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -34,4 +34,34 @@ public class StepHelpers { } return transportRequestId } + + public static getChangeDocumentId(ChangeManagement cm, def step, Map configuration) { + + def changeDocumentId = configuration.changeDocumentId + + if(changeDocumentId?.trim()) { + + step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." + + } else { + + step.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + + "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + + try { + changeDocumentId = cm.getChangeDocumentId( + configuration.changeManagement.git.from, + configuration.changeManagement.git.to, + configuration.changeManagement.changeDocumentLabel, + configuration.changeManagement.gitformat + ) + + step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" + + } catch(ChangeManagementException ex) { + step.echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." + } + } + return changeDocumentId + } } diff --git a/vars/checkChangeInDevelopment.groovy b/vars/checkChangeInDevelopment.groovy index 9d0f6dda2..5a9df7c11 100644 --- a/vars/checkChangeInDevelopment.groovy +++ b/vars/checkChangeInDevelopment.groovy @@ -8,6 +8,8 @@ import com.sap.piper.ConfigurationMerger import com.sap.piper.cm.ChangeManagement import com.sap.piper.cm.ChangeManagementException +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId + @Field def STEP_NAME = 'checkChangeInDevelopment' @Field Set stepConfigurationKeys = [ @@ -51,31 +53,7 @@ def call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME], configuration) - def changeId = configuration.changeDocumentId - - if(changeId?.trim()) { - - echo "[INFO] ChangeDocumentId retrieved from parameters." - - } else { - - echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - changeId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.git.format - ) - if(changeId?.trim()) { - echo "[INFO] ChangeDocumentId '${changeId}' retrieved from commit history" - } - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." - } - } + def changeId = getChangeDocumentId(cm, this, configuration) configuration = configHelper.mixin([changeDocumentId: changeId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('changeDocumentId', diff --git a/vars/transportRequestCreate.groovy b/vars/transportRequestCreate.groovy index 504ee725a..30281d6d4 100644 --- a/vars/transportRequestCreate.groovy +++ b/vars/transportRequestCreate.groovy @@ -9,6 +9,7 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId @Field def STEP_NAME = 'transportRequestCreate' @@ -47,31 +48,7 @@ def call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME], configuration) - def changeDocumentId = configuration.changeDocumentId - - if(changeDocumentId?.trim()) { - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." - - } else { - - echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - - changeDocumentId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.git.format - ) - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." - } - } + def changeDocumentId = getChangeDocumentId(cm, this, configuration) configuration = configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('changeDocumentId', diff --git a/vars/transportRequestRelease.groovy b/vars/transportRequestRelease.groovy index 77fe9ccb9..094583422 100644 --- a/vars/transportRequestRelease.groovy +++ b/vars/transportRequestRelease.groovy @@ -10,6 +10,7 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException import static com.sap.piper.cm.StepHelpers.getTransportRequestId +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId @Field def STEP_NAME = 'transportRequestRelease' @@ -50,32 +51,7 @@ def call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME], configuration) def transportRequestId = getTransportRequestId(cm, this, configuration) - - def changeDocumentId = configuration.changeDocumentId - - if(changeDocumentId?.trim()) { - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." - - } else { - - echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - changeDocumentId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.gitformat - ) - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" - - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." - } - } + def changeDocumentId = getChangeDocumentId(cm, this, configuration) configuration = configHelper .mixin([transportRequestId: transportRequestId?.trim() ?: null, diff --git a/vars/transportRequestUploadFile.groovy b/vars/transportRequestUploadFile.groovy index 4507b7e9d..8c5f7f794 100644 --- a/vars/transportRequestUploadFile.groovy +++ b/vars/transportRequestUploadFile.groovy @@ -10,6 +10,7 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException import static com.sap.piper.cm.StepHelpers.getTransportRequestId +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId @Field def STEP_NAME = 'transportRequestUploadFile' @@ -55,32 +56,7 @@ def call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME], configuration) - def changeDocumentId = configuration.changeDocumentId - - if(changeDocumentId?.trim()) { - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." - - } else { - - echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." - - try { - changeDocumentId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.git.format - ) - - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" - - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." - } - } - + def changeDocumentId = getChangeDocumentId(cm, this, configuration) def transportRequestId = getTransportRequestId(cm, this, configuration) configuration = configHelper From cfc7c5ecdcef83664c940bbc253fd2e66eeab830 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 5 Nov 2018 14:00:09 +0100 Subject: [PATCH 3/6] fix codeclimat issues --- src/com/sap/piper/cm/StepHelpers.groovy | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index a7193d2f8..d1a8fb8c9 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -16,14 +16,14 @@ public class StepHelpers { } else { step.echo "[INFO] Retrieving transport request id from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + " Searching for pattern '${configuration.changeManagement.transportRequestLabel}'. Searching with format '${configuration.changeManagement.git.format}'." try { transportRequestId = cm.getTransportRequestId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.transportRequestLabel, - configuration.changeManagement.git.format + configuration.changeManagement.git.from, + configuration.changeManagement.git.to, + configuration.changeManagement.transportRequestLabel, + configuration.changeManagement.git.format ) step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" From 3e75a8337da3f5e94bcfd6c0af683e7dbf32fac2 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 5 Nov 2018 14:03:36 +0100 Subject: [PATCH 4/6] fix codeclimat issues --- src/com/sap/piper/cm/StepHelpers.groovy | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index d1a8fb8c9..e0259176a 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -24,7 +24,7 @@ public class StepHelpers { configuration.changeManagement.git.to, configuration.changeManagement.transportRequestLabel, configuration.changeManagement.git.format - ) + ) step.echo "[INFO] Transport request id '${transportRequestId}' retrieved from commit history" @@ -47,14 +47,14 @@ public class StepHelpers { } else { step.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." try { changeDocumentId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.gitformat + configuration.changeManagement.git.from, + configuration.changeManagement.git.to, + configuration.changeManagement.changeDocumentLabel, + configuration.changeManagement.gitformat ) step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" From 3640ab63a4cba0ce579a9f6d8e7159fef8cccf80 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 5 Nov 2018 14:05:09 +0100 Subject: [PATCH 5/6] fix codeclimat issues --- src/com/sap/piper/cm/StepHelpers.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index e0259176a..63347bb49 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -55,7 +55,7 @@ public class StepHelpers { configuration.changeManagement.git.to, configuration.changeManagement.changeDocumentLabel, configuration.changeManagement.gitformat - ) + ) step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" From 48e76b6330f541804c5c7d764792fdf0389ebf79 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Mon, 5 Nov 2018 14:25:58 +0100 Subject: [PATCH 6/6] fix format retrieved in an invalid way from configuration --- src/com/sap/piper/cm/StepHelpers.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index 63347bb49..f0604d98f 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -47,14 +47,14 @@ public class StepHelpers { } else { step.echo "[INFO] Retrieving ChangeDocumentId from commit history [from: ${configuration.changeManagement.git.from}, to: ${configuration.changeManagement.git.to}]." + - "Searching for pattern '${configuration.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." + "Searching for pattern '${configuration.changeManagement.changeDocumentLabel}'. Searching with format '${configuration.changeManagement.git.format}'." try { changeDocumentId = cm.getChangeDocumentId( configuration.changeManagement.git.from, configuration.changeManagement.git.to, configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.gitformat + configuration.changeManagement.git.format ) step.echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history"