github.com/xgoffin/jenkins-library@v1.154.0/vars/transportRequestRelease.groovy (about)

     1  import static com.sap.piper.Prerequisites.checkScript
     2  
     3  import com.sap.piper.Utils
     4  import groovy.transform.Field
     5  
     6  import com.sap.piper.GenerateDocumentation
     7  import com.sap.piper.ConfigurationHelper
     8  import com.sap.piper.cm.BackendType
     9  import com.sap.piper.cm.ChangeManagement
    10  import com.sap.piper.cm.ChangeManagementException
    11  
    12  import hudson.AbortException
    13  
    14  import static com.sap.piper.cm.StepHelpers.getTransportRequestId
    15  import static com.sap.piper.cm.StepHelpers.getChangeDocumentId
    16  import static com.sap.piper.cm.StepHelpers.getBackendTypeAndLogInfoIfCMIntegrationDisabled
    17  
    18  @Field def STEP_NAME = getClass().getName()
    19  
    20  @Field Set GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
    21  
    22  @Field Set STEP_CONFIG_KEYS = [
    23      'changeManagement',
    24          /**
    25           * @see checkChangeInDevelopment
    26           * @parentConfigKey changeManagement
    27           */
    28          'clientOpts',
    29          /**
    30           * @see checkChangeInDevelopment
    31           * @parentConfigKey changeManagement
    32           */
    33          'credentialsId',
    34          /**
    35           * @see checkChangeInDevelopment
    36           * @parentConfigKey changeManagement
    37           */
    38          'endpoint',
    39          /**
    40           * @see checkChangeInDevelopment
    41           * @parentConfigKey changeManagement
    42           */
    43          'git/from',
    44          /**
    45           * @see checkChangeInDevelopment
    46           * @parentConfigKey changeManagement
    47           */
    48          'git/to',
    49          /**
    50           * @see checkChangeInDevelopment
    51           * @parentConfigKey changeManagement
    52           */
    53          'git/format',
    54          /**
    55           * @see transportRequestCreate
    56           * @parentConfigKey changeManagement
    57           */
    58          'rfc/developmentInstance',
    59          /**
    60           * @see transportRequestCreate
    61           * @parentConfigKey changeManagement
    62           */
    63          'rfc/developmentClient',
    64    ]
    65  
    66  @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
    67      /** @see transportRequestCreate */
    68      'changeDocumentId',
    69      /** The id of the transport request to release. */
    70      'transportRequestId',
    71      /** @see transportRequestCreate */
    72      'verbose',
    73  ])
    74  
    75  /** Releases a Transport Request. */
    76  @GenerateDocumentation
    77  void call(Map parameters = [:]) {
    78  
    79      handlePipelineStepErrors (stepName: STEP_NAME, stepParameters: parameters) {
    80  
    81          def script = checkScript(this, parameters) ?: this
    82          String stageName = parameters.stageName ?: env.STAGE_NAME
    83  
    84          ChangeManagement cm = parameters.cmUtils ?: new ChangeManagement(script)
    85  
    86          ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)
    87              .loadStepDefaults([:], stageName)
    88              .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
    89              .mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
    90              .mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
    91              .mixin(parameters, PARAMETER_KEYS)
    92  
    93          Map configuration = configHelper.use()
    94  
    95          BackendType backendType = getBackendTypeAndLogInfoIfCMIntegrationDisabled(this, configuration)
    96          if(backendType == BackendType.NONE) return
    97  
    98          configHelper
    99              .collectValidationFailures()
   100              .withMandatoryProperty('changeManagement/clientOpts')
   101              .withMandatoryProperty('changeManagement/credentialsId')
   102              .withMandatoryProperty('changeManagement/endpoint')
   103              .withMandatoryProperty('changeManagement/git/to')
   104              .withMandatoryProperty('changeManagement/git/from')
   105              .withMandatoryProperty('changeManagement/git/format')
   106              .withMandatoryProperty('changeManagement/rfc/developmentInstance', null, { backendType == BackendType.RFC})
   107              .withMandatoryProperty('changeManagement/rfc/developmentClient', null, { backendType == BackendType.RFC})
   108              .withMandatoryProperty('verbose', null, { backendType == BackendType.RFC})
   109  
   110          configuration = configHelper.use()
   111  
   112          new Utils().pushToSWA([
   113              step: STEP_NAME,
   114              stepParamKey1: 'scriptMissing',
   115              stepParam1: parameters?.script == null
   116          ], configuration)
   117  
   118          def changeDocumentId = null
   119          def transportRequestId = getTransportRequestId(cm, script, configuration)
   120  
   121          if(backendType == BackendType.SOLMAN) {
   122  
   123              changeDocumentId = getChangeDocumentId(cm, script, configuration)
   124  
   125              configHelper.mixin([changeDocumentId: changeDocumentId?.trim() ?: null], ['changeDocumentId'] as Set)
   126                          .withMandatoryProperty('changeDocumentId',
   127                              "Change document id not provided (parameter: \'changeDocumentId\' provided to the step call or via commit history).")
   128  
   129          }
   130  
   131          configuration = configHelper
   132                              .mixin([transportRequestId: transportRequestId?.trim() ?: null], ['transportRequestId'] as Set)
   133                              .withMandatoryProperty('transportRequestId',
   134                                  "Transport request id not provided (parameter: \'transportRequestId\' provided to the step call or via commit history).")
   135                              .use()
   136  
   137          def closingMessage = ["[INFO] Closing transport request '${configuration.transportRequestId}'"]
   138          if(backendType == BackendType.SOLMAN) closingMessage << " for change document '${configuration.changeDocumentId}'"
   139          closingMessage << '.'
   140          echo closingMessage.join()
   141  
   142              try {
   143  
   144                  switch(backendType) {
   145  
   146                      case BackendType.SOLMAN:
   147  
   148                          cm.releaseTransportRequestSOLMAN(
   149                              configuration.changeManagement.solman.docker,
   150                              configuration.changeDocumentId,
   151                              configuration.transportRequestId,
   152                              configuration.changeManagement.endpoint,
   153                              configuration.changeManagement.credentialsId,
   154                              configuration.changeManagement.clientOpts)
   155                          break
   156  
   157                      case BackendType.CTS:
   158  
   159                          cm.releaseTransportRequestCTS(
   160                              configuration.changeManagement.cts.docker,
   161                              configuration.transportRequestId,
   162                              configuration.changeManagement.endpoint,
   163                              configuration.changeManagement.credentialsId,
   164                              configuration.changeManagement.clientOpts)
   165                          break
   166  
   167                      case BackendType.RFC:
   168  
   169                          cm.releaseTransportRequestRFC(
   170                              configuration.changeManagement.rfc.docker,
   171                              configuration.transportRequestId,
   172                              configuration.changeManagement.endpoint,
   173                              configuration.changeManagement.rfc.developmentInstance,
   174                              configuration.changeManagement.rfc.developmentClient,
   175                              configuration.changeManagement.credentialsId,
   176                              configuration.verbose)
   177                          break
   178  
   179                      default:
   180  
   181                          throw new IllegalArgumentException("Invalid backend type: '${backendType}'.")
   182                  }
   183              } catch(ChangeManagementException ex) {
   184                  throw new AbortException(ex.getMessage())
   185              }
   186  
   187  
   188          echo "[INFO] Transport Request '${configuration.transportRequestId}' has been successfully closed."
   189      }
   190  }