1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

centralPipelineLoad step

A more convenient way to checkout the project sources. The idea is to
have a Jenkinsfile in the payload repository that only loads the shared
library and then runs this step. This step in turn loads a Jenkinsfile
from another repository.
The repo url, branch, Jenkinsfile path and credentials ID can be
provided to the step. The Jenkinsfile is first checked out to a
temporary folder, before it is loaded.
The payload repo must include a Jenkinsfile to be loaded with this
approach.
This commit is contained in:
Oliver Feldmann 2017-11-24 12:33:26 +01:00 committed by Marcus Holl
parent c47ff499fe
commit 5d5a82929c

View File

@ -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}"
}
}