I'm trying to setup a shared library within Jenkins that would have multiple git repositories and then multiple directory paths? Is this even possible? I've looked around a bit and the example's I have seen were here SparseCheckout in Jenkinsfile pipeline and then here Can I augment scm in Jenkinsfile? which just seems to say the same thing as above. I used the snippet generator to help create it but I do not know how it would call the specific repo and directory within the pipeline. Any advice or assistance is much appreciated. Here is the code from the snippet generator.
I just borrowed the define function from the stack overflow post above.
def call(scm, files) {
if (scm.class.simpleName == 'GitSCM') {
def filesAsPaths = files.collect {
[path: it]
}
return checkout([$class: 'GitSCM',
branches: [[name: '${GIT_BRANCH}']],
extensions: [[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: [[path: 'repo1/foo/'], [path: 'repo1/bar/'], [path: 'repo1/mike/'], [path: 'repo2/'], [path: 'repo3/']]]],
userRemoteConfigs: [[url: 'repo1'], [url: 'repo2'], [url: 'repo3']]])
} else {
// fallback to checkout everything by default
return checkout(scm)
}
}
You can create a new GitSCM object and pass it to the function. Example below. Also, have a look at this Class. You can use the costructor that suites you and update the checkout function accordingly.