1

I have a Jenkins job where I'm checking out 2 repos, The first repo "dev" contains src code and the Jenkinsfile and this repo is configured in Jenkins UI along with PollScm enabled. The second repo is "devops", I'm checking out this repo with sparse checkout in groovy script declarative pipeline.

        stage('Checkout DevopsScripts') {
        steps {
            script{
                dir('devops'){
                 def scmVar = checkout([$class: 'GitSCM', \
                    branches: [[name: '*/master']], \
                    doGenerateSubmoduleConfigurations: false, \
                    extensions: [[$class: 'SparseCheckoutPaths',  sparseCheckoutPaths:[[$class:'SparseCheckoutPath', path:'Scripts/testScript/']]]], \
                    submoduleCfg: [], \
                    userRemoteConfigs: [[credentialsId: 'XXXXXXX', url: "https://github.com/org/devops.git"]], \
                    poll: false, \
                    changelog: false
                    ])
                }
            }
        }
    }

Now I want PollScm to happen only for the commits happening in the "dev" repo, PollScm should ignore commits happening in "devops" repo. But even after enabling poll: false Jenkins job triggers on any commits happening in either repo. I have scrolled through the document "https://plugins.jenkins.io/workflow-scm-step/" which says "You may specify poll: false to disable polling for an SCM checkout" which is not happening in my case. Is there a bug in Jenkins related to this issue or I'm missing anything here.

Kalim
  • 189
  • 1
  • 3
  • 12

2 Answers2

1

Check, as in here, if a trigger directive (Jenkins 2.22 or later) can separate:

  • the pipeline start
  • from the pipeline step (Git repository checkout)

Something similar to:

pipeline {
    agent any
    triggers {
        pollSCM('H 0-23/4 * * 1-5')
    }
    stages {
        stage('Checkout') {
            steps {
                checkout scm: [$class: 'GitSCM', 
                               branches: [[name: '*/master']], 
                               doGenerateSubmoduleConfigurations: false, 
                               extensions: [], submoduleCfg: [], 
                               userRemoteConfigs: [[url: 'https://github.com/jenkinsci/jenkins.git']]]
            }
        }
    }
}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

This is a known bug in Jenkins that is unfixed as of 2022-11-23. See Jenkins-60757 on the bug tracker: '"poll: false" has no effect in scm (and git) pipeline steps'.

So, basically the poll: false flag doesn't work right now.

ingyhere
  • 11,818
  • 3
  • 38
  • 52