1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00
sap-jenkins-library/vars/transportRequestRelease.groovy
Marcus Holl 52bb1e842d Validate required parameters via config helper
- In case a parameter is missing we do not thrown and AbortException
    anmore, but an IllegalArgumentExcpetion, since that exception is
    thrown by the configuration helper. The difference is: AbortExceptions
    are contained in the log without stacktrace, other exceptions are
    printed with stack trace.
  - Exception messages are changed to the standard error message triggered
    inside the configuration helper. In case the changeDocumentId is
    retrieved also from the commit history we keep an exception message
    pointing to that.
  - Having references to the parameters is droped. Instead the parameters
    are directly used from the configuration map.
  - in case of long signatures line breaks are inserted in order to
    simplify reading the code.
2018-07-12 09:34:06 +02:00

71 lines
2.6 KiB
Groovy

import com.sap.piper.GitUtils
import groovy.transform.Field
import com.sap.piper.ConfigurationHelper
import com.sap.piper.ConfigurationMerger
import com.sap.piper.cm.ChangeManagement
import com.sap.piper.cm.ChangeManagementException
import hudson.AbortException
@Field def STEP_NAME = 'transportRequestRelease'
@Field Set parameterKeys = [
'changeDocumentId',
'cmClientOpts',
'transportRequestId',
'credentialsId',
'endpoint'
]
@Field Set stepConfigurationKeys = [
'credentialsId',
'cmClientOpts',
'endpoint'
]
@Field Set generalConfigurationKeys = stepConfigurationKeys
def call(parameters = [:]) {
handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
ChangeManagement cm = new ChangeManagement(script)
Map configuration = ConfigurationHelper
.loadStepDefaults(this)
.mixinGeneralConfig(script.commonPipelineEnvironment, generalConfigurationKeys)
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, stepConfigurationKeys)
.mixinStepConfig(script.commonPipelineEnvironment, stepConfigurationKeys)
.mixin(parameters, parameterKeys)
.withMandatoryProperty('changeDocumentId')
.withMandatoryProperty('transportRequestId')
.withMandatoryProperty('endpoint')
.use()
echo "[INFO] Closing transport request '${configuration.transportRequestId}' for change document '${configuration.changeDocumentId}'."
withCredentials([usernamePassword(
credentialsId: configuration.credentialsId,
passwordVariable: 'password',
usernameVariable: 'username')]) {
try {
cm.releaseTransportRequest(configuration.changeDocumentId,
configuration.transportRequestId,
configuration.endpoint,
username,
password,
configuration.cmClientOpts)
} catch(ChangeManagementException ex) {
throw new AbortException(ex.getMessage())
}
}
echo "[INFO] Transport Request '${configuration.transportRequestId}' has been successfully closed."
}
}