github.com/jaylevin/jenkins-library@v1.230.4/vars/pipelineExecute.groovy (about) 1 import com.sap.piper.GenerateDocumentation 2 import com.sap.piper.ConfigurationHelper 3 4 import groovy.transform.Field 5 6 7 @Field STEP_NAME = getClass().getName() 8 9 @Field Set GENERAL_CONFIG_KEYS = [] 10 11 @Field Set STEP_CONFIG_KEYS = [] 12 13 @Field Set PARAMETER_KEYS = [ 14 /** The url to the git repository of the pipeline to be loaded.*/ 15 'repoUrl', 16 /** The branch of the git repository from which the pipeline should be checked out.*/ 17 'branch', 18 /** The path to the Jenkinsfile, inside the repository, to be loaded.*/ 19 'path', 20 /** 21 * The Jenkins credentials containing user and password needed to access a private git repository. 22 * In case access to the repository containing the pipeline script is restricted the credentialsId of the credentials used for 23 * accessing the repository needs to be provided. The corresponding credentials needs to be configured in Jenkins accordingly. 24 */ 25 'credentialsId' 26 ] 27 28 /** 29 * Loads and executes a pipeline from another git repository. 30 * The idea is to set up a pipeline job in Jenkins that loads a minimal pipeline, which 31 * in turn loads the shared library and then uses this step to load the actual pipeline. 32 * 33 * A centrally maintained pipeline script (Jenkinsfile) can be re-used by 34 * several projects using `pipelineExecute` as outlined in the example below. 35 */ 36 @GenerateDocumentation 37 void call(Map parameters = [:]) { 38 39 node() { 40 41 Map config 42 43 handlePipelineStepErrors (stepName: 'pipelineExecute', stepParameters: parameters, failOnError: true) { 44 45 ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this) 46 .loadStepDefaults() 47 .mixin(parameters, PARAMETER_KEYS) 48 .withMandatoryProperty('repoUrl') 49 .withMandatoryProperty('branch') 50 .withMandatoryProperty('path') 51 .withMandatoryProperty('credentialsId') 52 53 config = configHelper.use() 54 55 deleteDir() 56 57 checkout([ 58 $class: 'GitSCM', 59 branches: [[name: config.branch]], 60 doGenerateSubmoduleConfigurations: false, 61 extensions: [[ 62 $class: 'SparseCheckoutPaths', 63 sparseCheckoutPaths: [[path: config.path]] 64 ]], 65 submoduleCfg: [], 66 userRemoteConfigs: [[ 67 credentialsId: config.credentialsId, 68 url: config.repoUrl 69 ]] 70 ]) 71 72 } 73 load config.path 74 } 75 }