diff --git a/resources/default_pipeline_environment.yml b/resources/default_pipeline_environment.yml index f157da12e..f83abea0b 100644 --- a/resources/default_pipeline_environment.yml +++ b/resources/default_pipeline_environment.yml @@ -3,6 +3,7 @@ general: productiveBranch: 'master' collectTelemetryData: true changeManagement: + type: 'SOLMAN' # SOLMAN, CTS transportRequestLabel: 'TransportRequest\s?:' changeDocumentLabel: 'ChangeDocument\s?:' clientOpts: '' diff --git a/test/groovy/TransportRequestUploadFileTest.groovy b/test/groovy/TransportRequestUploadFileTest.groovy index 814ce7b26..5e32a02c0 100644 --- a/test/groovy/TransportRequestUploadFileTest.groovy +++ b/test/groovy/TransportRequestUploadFileTest.groovy @@ -291,4 +291,17 @@ public class TransportRequestUploadFileTest extends BasePiperTest { cmUtils: cm) } + @Test + public void invalidBackendTypeTest() { + thrown.expect(AbortException) + thrown.expectMessage('Invalid backend type: \'DUMMY\'. Valid values: [SOLMAN, CTS, NONE]. ' + + 'Configuration: \'changeManagement/type\'.') + + jsr.step.call(script: nullScript, + applicationId: 'app', + filePath: '/path', + changeManagement: [type: 'DUMMY']) + + } + } diff --git a/vars/transportRequestUploadFile.groovy b/vars/transportRequestUploadFile.groovy index 98d388667..ab5a40559 100644 --- a/vars/transportRequestUploadFile.groovy +++ b/vars/transportRequestUploadFile.groovy @@ -9,7 +9,6 @@ import com.sap.piper.cm.ChangeManagementException import hudson.AbortException - @Field def STEP_NAME = 'transportRequestUploadFile' @Field Set generalConfigurationKeys = [ @@ -45,6 +44,7 @@ def call(parameters = [:]) { .withMandatoryProperty('changeManagement/clientOpts') .withMandatoryProperty('changeManagement/credentialsId') .withMandatoryProperty('changeManagement/endpoint') + .withMandatoryProperty('changeManagement/type') .withMandatoryProperty('changeManagement/git/from') .withMandatoryProperty('changeManagement/git/to') .withMandatoryProperty('changeManagement/git/format') @@ -52,31 +52,46 @@ def call(parameters = [:]) { Map configuration = configHelper.use() - new Utils().pushToSWA([step: STEP_NAME], configuration) + new Utils().pushToSWA([step: STEP_NAME, stepParam1: configuration.changeManagement.type], configuration) - def changeDocumentId = configuration.changeDocumentId + ChangeManagement.BackendType backendType - if(changeDocumentId?.trim()) { + try { + backendType = configuration.changeManagement.type as ChangeManagement.BackendType + } catch(IllegalArgumentException e) { + error "Invalid backend type: '${configuration.changeManagement.type}'. " + + "Valid values: [${ChangeManagement.BackendType.values().join(', ')}]. " + + "Configuration: 'changeManagement/type'." + } - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." + def changeDocumentId = null - } else { + if(backendType == ChangeManagement.BackendType.SOLMAN) { - 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}'." + changeDocumentId = configuration.changeDocumentId - try { - changeDocumentId = cm.getChangeDocumentId( - configuration.changeManagement.git.from, - configuration.changeManagement.git.to, - configuration.changeManagement.changeDocumentLabel, - configuration.changeManagement.git.format - ) + if(changeDocumentId?.trim()) { - echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from commit history" + echo "[INFO] ChangeDocumentId '${changeDocumentId}' retrieved from parameters." - } catch(ChangeManagementException ex) { - echo "[WARN] Cannot retrieve changeDocumentId from commit history: ${ex.getMessage()}." + } 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()}." + } } } @@ -106,16 +121,26 @@ def call(parameters = [:]) { } } + configHelper + .mixin([changeDocumentId: changeDocumentId?.trim() ?: null, + transportRequestId: transportRequestId?.trim() ?: null], ['changeDocumentId', 'transportRequestId'] as Set) + + if(backendType == ChangeManagement.BackendType.SOLMAN) { + configHelper + .withMandatoryProperty('changeDocumentId', + "Change document id not provided (parameter: \'changeDocumentId\' or via commit history).") + } configuration = configHelper - .mixin([changeDocumentId: changeDocumentId?.trim() ?: null, - transportRequestId: transportRequestId?.trim() ?: null], ['changeDocumentId', 'transportRequestId'] as Set) - .withMandatoryProperty('changeDocumentId', - "Change document id not provided (parameter: \'changeDocumentId\' or via commit history).") - .withMandatoryProperty('transportRequestId', + .withMandatoryProperty('transportRequestId', "Transport request id not provided (parameter: \'transportRequestId\' or via commit history).") .use() - echo "[INFO] Uploading file '${configuration.filePath}' to transport request '${configuration.transportRequestId}' of change document '${configuration.changeDocumentId}'." + def uploadingMessage = ["[INFO] Uploading file '${configuration.filePath}' to transport request '${configuration.transportRequestId}'"] + if(backendType == ChangeManagement.BackendType.SOLMAN) + uploadingMessage << " of change document '${configuration.changeDocumentId}'" + uploadingMessage << '.' + + echo uploadingMessage.join() try { @@ -133,6 +158,10 @@ def call(parameters = [:]) { } - echo "[INFO] File '${configuration.filePath}' has been successfully uploaded to transport request '${configuration.transportRequestId}' of change document '${configuration.changeDocumentId}'." + def uploadedMessage = ["[INFO] File '${configuration.filePath}' has been successfully uploaded to transport request '${configuration.transportRequestId}'"] + if(backendType == ChangeManagement.BackendType.SOLMAN) + uploadedMessage << " of change document '${configuration.changeDocumentId}'" + uploadedMessage << '.' + echo uploadedMessage.join() } }