很遗憾,Jenkins Bitbucket 和 Jenkins GitHub 插件不提供监视来自多个 git 存储库的钩子的功能。
您的问题的可能解决方案包括:
// Single pipeline example
pipeline {
agent any
stages {
stage("I'm just printing a message in here") {
steps {
script {
print('Yep, just printing some happy message')
}
}
}
stage("Cloning repository A") {
steps {
script {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'my-repo-a']], userRemoteConfigs: [[credentialsId: 'MY-GIT-CREDENTIALS', url: 'https://github.com/my-user/my-repo-a.git']]])
}
}
}
}
}
- 有两条管道。一个主要的(我们称之为 PIPELINE-A),它将被钩子调用,一个辅助(我们称之为 PIPELINE-B),它将克隆其他存储库并做一些有趣的事情:
// PIPELINE-A
pipeline {
agent any
stages {
stage('Calling PIPELINE-B') {
steps {
script {
build 'pipeline-b'
}
}
}
}
}
// PIPELINE-B
pipeline {
agent any
stages {
stage('Cloning Git repository') {
steps {
script {
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'my-repo-a']], userRemoteConfigs: [[credentialsId: 'MY-GIT-CREDENTIAL', url: 'https://github.com/my-user/my-repo-a.git']]])
checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'my-repo-b']], userRemoteConfigs: [[credentialsId: 'MY-GIT-CREDENTIAL', url: 'https://github.com/my-user/my-repo-b.git']]])
}
}
}
}
}
使用此解决方案,您可以将每个存储库克隆到不同的文件夹中。因此,在那之后,您应该在对该项目执行任何特定任务之前对该文件夹执行cd。为了更好地组织,您可以为不同的存储库设置不同的管道,如果您愿意,可以包含其任务,但作为最后两种解决方案的结合,您将不得不选择一个主存储库来触发您的工作。
最好的问候!