2019-04-01 15:08:37 +02:00
|
|
|
import com.sap.piper.GenerateDocumentation
|
2017-11-24 13:33:26 +02:00
|
|
|
import com.sap.piper.Utils
|
|
|
|
|
2018-10-09 17:09:55 +02:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field STEP_NAME = getClass().getName()
|
2018-10-09 17:09:55 +02:00
|
|
|
|
2019-04-04 17:01:30 +02:00
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
|
|
|
|
|
|
|
@Field Set STEP_CONFIG_KEYS = []
|
|
|
|
|
2019-04-01 15:08:37 +02:00
|
|
|
@Field Set PARAMETER_KEYS = [
|
|
|
|
/** The url to the git repository of the pipeline to be loaded.*/
|
|
|
|
'repoUrl',
|
|
|
|
/** The branch of the git repository from which the pipeline should be checked out.*/
|
|
|
|
'branch',
|
|
|
|
/** The path to the Jenkinsfile, inside the repository, to be loaded.*/
|
|
|
|
'path',
|
|
|
|
/** The Jenkins credentials containing user and password needed to access a private git repository.*/
|
|
|
|
'credentialsId'
|
|
|
|
]
|
2018-10-09 17:09:55 +02:00
|
|
|
|
2017-11-24 13:33:26 +02:00
|
|
|
/**
|
2019-04-01 15:08:37 +02:00
|
|
|
* Loads and executes a pipeline from another git repository.
|
|
|
|
* The idea is to set up a pipeline job in Jenkins that loads a minimal pipeline, which
|
|
|
|
* in turn loads the shared library and then uses this step to load the actual pipeline.
|
2017-11-24 13:33:26 +02:00
|
|
|
*
|
2019-04-01 15:08:37 +02:00
|
|
|
* A centrally maintained pipeline script (Jenkinsfile) can be re-used by
|
|
|
|
* several projects using `pipelineExecute` as outlined in the example below.
|
2017-11-24 13:33:26 +02:00
|
|
|
*/
|
2019-04-01 15:08:37 +02:00
|
|
|
@GenerateDocumentation
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2017-11-24 13:33:26 +02:00
|
|
|
|
2017-12-01 18:00:30 +02:00
|
|
|
node() {
|
2017-11-24 13:33:26 +02:00
|
|
|
|
2017-12-01 18:00:30 +02:00
|
|
|
def path
|
2017-11-24 13:33:26 +02:00
|
|
|
|
2017-12-01 18:00:30 +02:00
|
|
|
handlePipelineStepErrors (stepName: 'pipelineExecute', stepParameters: parameters) {
|
2017-11-24 13:33:26 +02:00
|
|
|
|
2017-12-01 18:00:30 +02:00
|
|
|
def utils = new Utils()
|
|
|
|
|
|
|
|
// The coordinates of the pipeline script
|
|
|
|
def repo = utils.getMandatoryParameter(parameters, 'repoUrl', null)
|
|
|
|
def branch = utils.getMandatoryParameter(parameters, 'branch', 'master')
|
|
|
|
|
|
|
|
path = utils.getMandatoryParameter(parameters, 'path', 'Jenkinsfile')
|
|
|
|
|
|
|
|
// In case access to the repository containing the 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', '')
|
2017-11-24 13:33:26 +02:00
|
|
|
|
2017-11-28 10:34:54 +02:00
|
|
|
deleteDir()
|
2017-11-24 13:33:26 +02:00
|
|
|
|
|
|
|
checkout([$class: 'GitSCM', branches: [[name: branch]],
|
|
|
|
doGenerateSubmoduleConfigurations: false,
|
|
|
|
extensions: [[$class: 'SparseCheckoutPaths',
|
|
|
|
sparseCheckoutPaths: [[path: path]]
|
|
|
|
]],
|
|
|
|
submoduleCfg: [],
|
|
|
|
userRemoteConfigs: [[credentialsId: credentialsId,
|
|
|
|
url: repo
|
|
|
|
]]
|
|
|
|
])
|
|
|
|
|
2017-11-28 10:34:54 +02:00
|
|
|
}
|
2017-12-01 18:00:30 +02:00
|
|
|
load path
|
2017-11-24 13:33:26 +02:00
|
|
|
}
|
|
|
|
}
|