2018-06-20 11:52:11 +02:00
|
|
|
import com.sap.piper.GitUtils
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
2018-07-06 09:05:26 +02:00
|
|
|
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 parameterKeys = [
|
2018-06-28 08:46:23 +02:00
|
|
|
'changeDocumentId',
|
2018-06-29 15:14:09 +02:00
|
|
|
'cmClientOpts',
|
2018-06-20 11:52:11 +02:00
|
|
|
'transportRequestId',
|
2018-06-28 16:24:14 +02:00
|
|
|
'credentialsId',
|
|
|
|
'endpoint'
|
2018-06-20 11:52:11 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
@Field Set stepConfigurationKeys = [
|
2018-06-28 16:24:14 +02:00
|
|
|
'credentialsId',
|
2018-06-29 15:14:09 +02:00
|
|
|
'cmClientOpts',
|
2018-06-28 16:24:14 +02:00
|
|
|
'endpoint'
|
2018-06-20 11:52:11 +02:00
|
|
|
]
|
|
|
|
|
2018-07-06 09:05:26 +02:00
|
|
|
@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)
|
|
|
|
|
2018-07-06 09:05:26 +02:00
|
|
|
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)
|
|
|
|
.use()
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2018-06-28 08:46:23 +02:00
|
|
|
def changeDocumentId = configuration.changeDocumentId
|
|
|
|
if(!changeDocumentId) throw new AbortException("Change document id not provided (parameter: 'changeDocumentId').")
|
2018-06-20 11:52:11 +02:00
|
|
|
|
|
|
|
def transportRequestId = configuration.transportRequestId
|
|
|
|
if(!transportRequestId) throw new AbortException("Transport Request id not provided (parameter: 'transportRequestId').")
|
|
|
|
|
2018-06-28 16:24:14 +02:00
|
|
|
def credentialsId = configuration.credentialsId
|
|
|
|
if(!credentialsId) throw new AbortException("Credentials id not provided (parameter: 'credentialsId').")
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2018-06-28 16:24:14 +02:00
|
|
|
def endpoint = configuration.endpoint
|
|
|
|
if(!endpoint) throw new AbortException("Solution Manager endpoint not provided (parameter: 'endpoint').")
|
2018-06-20 11:52:11 +02:00
|
|
|
|
2018-06-28 08:46:23 +02:00
|
|
|
echo "[INFO] Closing transport request '$transportRequestId' for change document '$changeDocumentId'."
|
2018-06-20 11:52:11 +02:00
|
|
|
|
|
|
|
withCredentials([usernamePassword(
|
2018-06-28 16:24:14 +02:00
|
|
|
credentialsId: credentialsId,
|
2018-06-20 11:52:11 +02:00
|
|
|
passwordVariable: 'password',
|
|
|
|
usernameVariable: 'username')]) {
|
|
|
|
|
|
|
|
try {
|
2018-06-29 15:14:09 +02:00
|
|
|
cm.releaseTransportRequest(changeDocumentId, transportRequestId, endpoint, username, password, configuration.cmClientOpts)
|
2018-06-20 11:52:11 +02:00
|
|
|
} catch(ChangeManagementException ex) {
|
|
|
|
throw new AbortException(ex.getMessage())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "[INFO] Transport Request '${transportRequestId}' has been successfully closed."
|
|
|
|
}
|
|
|
|
}
|