Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a job by polling multiple GIT repos inside Jenkinsfile

At the Jenkinsfile with two git repositories these is an example of using multiple GIT repositories in a single Jenkins job:

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')
}

How can I configure this job to track SCM changes of these 2 repositories so that the job triggers each time when at least one of repositories has updates?

The problem is that the job is polling not the repositories mentioned inside Jenkinsfile, but the repository of the Jenkinsfile itself (it is stored in a special repository, not with the source code together) which is mentioned in the GUI configuration of the job.

With the old Jenkins (without coded pipeline) and SVN plugin it was very easy, because all N repositories could be mentioned in the GUI configuration, checked out to a separate sub-directories of the single workspace and simultaneously polled.

How can I reach the same result with GIT + Jenkins Pipeline-As-Code? I tried to use also "poll: true" option in the Jenkinsfile, but it did not help. What does then this option do?

UPDATE 1: Here is the pipeline script which I really use and which does not work:

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') {
    ...
  }
like image 523
Alexander Samoylov Avatar asked Nov 22 '17 16:11

Alexander Samoylov


Video Answer


1 Answers

I found the cause of the problem. It was a fault described by https://issues.jenkins-ci.org/browse/JENKINS-37731. I used a wrong syntax. The correct one looks so:

properties([
    pipelineTriggers([
        [$class: "SCMTrigger", scmpoll_spec: "H/5 * * * *"],
    ])
])
like image 158
Alexander Samoylov Avatar answered Nov 15 '22 08:11

Alexander Samoylov