diff --git a/vars/centralPipelineLoad.groovy b/vars/centralPipelineLoad.groovy new file mode 100644 index 000000000..029773ce3 --- /dev/null +++ b/vars/centralPipelineLoad.groovy @@ -0,0 +1,45 @@ +import com.sap.piper.Utils + +/** + * centralPipelineLoad + * Load a central pipeline. + * + */ +def call(Map parameters = [:]) { + + handlePipelineStepErrors (stepName: 'centralPipelineLoad', stepParameters: parameters) { + + def utils = new Utils() + + // The coordinates of the central pipeline script + def repo = utils.getMandatoryParameter(parameters, 'repoUrl', null) + def branch = utils.getMandatoryParameter(parameters, 'branch', 'master') + def path = utils.getMandatoryParameter(parameters, 'jenkinsfilePath', 'Jenkinsfile') + + // In case access to the repository containing the central pipeline + // script is restricted the credentialsId of the credentials used for + // accessing the repository needs to be provided below. The corresponding + // credentials needs to be configured in Jenkins accordingly. + def credentialsId = utils.getMandatoryParameter(parameters, 'credentialsId', '') + + // temporary folder used for storing the central jenkins file locally. + def temporaryPipelineFolder = "pipeline-${UUID.randomUUID().toString()}" + + deleteDir() + dir(temporaryPipelineFolder) { + + checkout([$class: 'GitSCM', branches: [[name: branch]], + doGenerateSubmoduleConfigurations: false, + extensions: [[$class: 'SparseCheckoutPaths', + sparseCheckoutPaths: [[path: path]] + ]], + submoduleCfg: [], + userRemoteConfigs: [[credentialsId: credentialsId, + url: repo + ]] + ]) + } + + load "${temporaryPipelineFolder}/${path}" + } +}