通过轮询Jenkinsfile中的多个GIT存储库来触发作业

Ale*_*lov 5 git polling jenkins-pipeline

具有两个git存储库Jenkinsfile中,这些是在单个Jenkins作业中使用多个GIT存储库的示例:

node {
    dir('RepoOne') {
        git url: 'https://github.com/somewhere/RepoOne.git'
    }
    dir('RepoTwo') {
        git url: 'https://github.com/somewhere/RepoTwo.git'
    }

    sh('. RepoOne/build.sh')
    sh('. RepoTwo/build.sh')
}
Run Code Online (Sandbox Code Playgroud)

如何配置此作业以跟踪这两个存储库的SCM更改,以便每次至少有一个存储库具有更新时触发该作业?

问题在于,作业不是轮询Jenkinsfile内提到的存储库,而是轮询Jenkinsfile本身的存储库(它存储在特殊的存储库中,而不是与源代码一起存储),这是在作业的GUI配置中提到的。

使用旧的Jenkins(无编码管道)和SVN插件,这非常容易,因为可以在GUI配置中提及所有N个存储库,将其检出到单个工作空间的单独子目录并同时进行轮询。

如何使用GIT + Jenkins Pipeline-As-Code获得相同的结果?我尝试在Jenkinsfile中也使用“ poll:true”选项,但没有帮助。那么此选项有什么作用?

更新1:这是我真正使用的管道脚本,但是它不起作用:

properties([
    pipelineTriggers([
        scm('H/5 * * * *')
    ])
])

node {
  stage ('Checkout') {
    dir('cplib') {
      git(
      poll: true,
          url: 'ssh://git@<server>:<port>/base/cplib.git',
          credentialsId: 'BlueOceanMsl',
          branch: 'master'
      )
    }
    dir('cpmffmeta') {
      git(
      poll: true,
          url: 'ssh://git@<server>:<port>/base/cpmffmeta.git',
          credentialsId: 'BlueOceanMsl',
          branch: 'master'
        )
    }
  }

  stage ('Build') {
    ...
  }
Run Code Online (Sandbox Code Playgroud)

Jak*_*ake 0

git 步骤应该有一个“轮询”选项,您将其设置为 true,然后将作业配置为轮询 scm 更改。您还可以使用通用 scm 步骤进行 git checkout 并确保其配置为轮询。如果设置“poll: true”不起作用,那么我怀疑这是一个错误。但是,您可能确实需要首先手动运行至少一项作业。