diff --git a/src/com/sap/piper/cm/StepHelpers.groovy b/src/com/sap/piper/cm/StepHelpers.groovy index 6b21bbde4..f0604d98f 100644 --- a/src/com/sap/piper/cm/StepHelpers.groovy +++ b/src/com/sap/piper/cm/StepHelpers.groovy @@ -4,6 +4,68 @@ 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 + } + + @NonCPS + 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.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 + ) + + 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 + } + @NonCPS static BackendType getBackendTypeAndLogInfoIfCMIntegrationDisabled(def step, Map configuration) { diff --git a/vars/checkChangeInDevelopment.groovy b/vars/checkChangeInDevelopment.groovy index e7b471037..e63b489be 100644 --- a/vars/checkChangeInDevelopment.groovy +++ b/vars/checkChangeInDevelopment.groovy @@ -11,6 +11,7 @@ import com.sap.piper.cm.BackendType import com.sap.piper.cm.ChangeManagement import com.sap.piper.cm.ChangeManagementException +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled @Field def STEP_NAME = 'checkChangeInDevelopment' @@ -93,37 +94,10 @@ void call(parameters = [:]) { */ .withMandatoryProperty('changeManagement/endpoint') - - configuration = configHelper.use() - new Utils().pushToSWA([step: STEP_NAME, stepParam1: parameters?.script == null], 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) @@ -142,7 +116,6 @@ void call(parameters = [:]) { try { - isInDevelopment = cm.isChangeInDevelopment(configuration.changeDocumentId, configuration.changeManagement.endpoint, configuration.changeManagement.credentialsId, diff --git a/vars/transportRequestCreate.groovy b/vars/transportRequestCreate.groovy index 246bf3a95..1fec7d580 100644 --- a/vars/transportRequestCreate.groovy +++ b/vars/transportRequestCreate.groovy @@ -10,6 +10,7 @@ import com.sap.piper.cm.ChangeManagementException import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled +import static com.sap.piper.cm.StepHelpers.getChangeDocumentId import hudson.AbortException @Field def STEP_NAME = 'transportRequestCreate' @@ -67,31 +68,8 @@ def call(parameters = [:]) { if(backendType == BackendType.SOLMAN) { - changeDocumentId = configuration.changeDocumentId + changeDocumentId = getChangeDocumentId(cm, this, configuration) - 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()}." - } - } configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('developmentSystemId') .withMandatoryProperty('changeDocumentId', diff --git a/vars/transportRequestRelease.groovy b/vars/transportRequestRelease.groovy index add9b504c..9c28d7dcd 100644 --- a/vars/transportRequestRelease.groovy +++ b/vars/transportRequestRelease.groovy @@ -10,6 +10,8 @@ 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 import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled @Field def STEP_NAME = 'transportRequestRelease' @@ -59,61 +61,12 @@ void call(parameters = [:]) { new Utils().pushToSWA([step: STEP_NAME, stepParam1: parameters?.script == null], 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 changeDocumentId = null + def transportRequestId = getTransportRequestId(cm, this, configuration) if(backendType == BackendType.SOLMAN) { - 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()}." - } - } + changeDocumentId = getChangeDocumentId(cm, this, configuration) configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set) .withMandatoryProperty('changeDocumentId', diff --git a/vars/transportRequestUploadFile.groovy b/vars/transportRequestUploadFile.groovy index 6cb7a069b..420b59592 100644 --- a/vars/transportRequestUploadFile.groovy +++ b/vars/transportRequestUploadFile.groovy @@ -10,6 +10,8 @@ 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 import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled @Field def STEP_NAME = 'transportRequestUploadFile' @@ -66,59 +68,10 @@ void call(parameters = [:]) { def changeDocumentId = null if(backendType == BackendType.SOLMAN) { - - 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()}." - } - } + changeDocumentId = getChangeDocumentId(cm, this, 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.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) configHelper .mixin([changeDocumentId: changeDocumentId?.trim() ?: null,