6

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') {
    ...
  }
Alexander Samoylov
  • 2,358
  • 2
  • 25
  • 28

2 Answers2

4

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 * * * *"],
    ])
])
Alexander Samoylov
  • 2,358
  • 2
  • 25
  • 28
0

The git step should have a "polling" option, which you set to true, and then the job is configured to poll on scm change. You can also use the generic scm step to so the git checkout and make sure it's configured to poll. If setting "poll: true" doesn't work, then I suspect it's a bug. However, you probably do need to run at least one job manually first.

Jake
  • 199
  • 2
  • 5
  • I know that I must run the job manually one time in order to bring the settings from the pipeline script to effect. But even after that it did not work. I am surprised that you are talking about a bug, because how then other users of scripted pipeline manage such a classical use-case? – Alexander Samoylov Nov 27 '17 at 10:19