1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/vars/transportRequestRelease.groovy

68 lines
2.7 KiB
Groovy
Raw Normal View History

2018-06-20 11:52:11 +02:00
import com.sap.piper.GitUtils
import groovy.transform.Field
import com.sap.piper.ConfigurationHelper
2018-06-20 11:52:11 +02:00
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 stepConfigurationKeys = [
'changeManagement'
2018-06-20 11:52:11 +02:00
]
@Field Set parameterKeys = stepConfigurationKeys.plus([
'changeDocumentId',
'transportRequestId',
])
@Field Set generalConfigurationKeys = stepConfigurationKeys
2018-06-20 11:52:11 +02:00
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('changeManagement/clientOpts')
.withMandatoryProperty('changeManagement/credentialsId')
.withMandatoryProperty('changeManagement/endpoint')
.use()
2018-06-20 11:52:11 +02:00
echo "[INFO] Closing transport request '${configuration.transportRequestId}' for change document '${configuration.changeDocumentId}'."
2018-06-20 11:52:11 +02:00
withCredentials([usernamePassword(
credentialsId: configuration.changeManagement.credentialsId,
2018-06-20 11:52:11 +02:00
passwordVariable: 'password',
usernameVariable: 'username')]) {
try {
cm.releaseTransportRequest(configuration.changeDocumentId,
configuration.transportRequestId,
configuration.changeManagement.endpoint,
username,
password,
configuration.changeManagement.clientOpts)
2018-06-20 11:52:11 +02:00
} catch(ChangeManagementException ex) {
throw new AbortException(ex.getMessage())
}
}
echo "[INFO] Transport Request '${configuration.transportRequestId}' has been successfully closed."
2018-06-20 11:52:11 +02:00
}
}