我试图在Jenkins中建立一个共享库,它将有多个git仓库和多个目录路径?这可能吗?我四处查看了一下,我看到的例子是这里的SparseCheckout in Jenkinsfile pipeline,然后这里的Can I augment scm in Jenkinsfile?,看起来和上面说的一样。我使用了snippet生成器来帮助创建它,但我不知道它将如何调用管道中的特定repo和目录。任何建议或帮助都非常感谢。以下是snippet生成器的代码。
我只是从上面的堆栈溢出帖子中借用了define函数。
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)
}
}
1条答案
按热度按时间dwthyt8l1#
你可以创建一个新的GitSCM对象并将其传递给函数。示例如下。另外,看看这个Class。你可以使用适合你的构造函数并相应地更新checkout函数。