Jenkinsfile poll specific repository

I am executing a job from my jenkinsfile to specify parameters i want to have in this automated run. The problem I face is that pollSCM doesn’t allow me to specifiy the repo that is to be polled. I want to poll the repo that is checked out in the build i will be starting and not the one where the jenkinsfile is located. Is there a way to achieve that?

rough pipeline script:

pipeline {
    agent any
    triggers {

        pollSCM(pollSCM:'* * * * *', repos: [[url: 'gitlab.git']]) <------ doesn't work

    stages {
        stage('Build') {
            steps {
                build job: 'multiparam build', parameters: [


Jenkins setup:

As you already found out, the pollSCM trigger in Jenkins Pipeline is designed to poll the SCM of the Jenkinsfile’s own repository. :person_shrugging:
As far as I know, it doesn’t support polling other repositories directly.

You could maybe achieve your goal by creating a separate Jenkins job that is responsible for polling the desired repository.
I know, that’s not pretty.
This job could be a simple Freestyle job or Pipeline job that is configured to poll the SCM of the desired repository. :thinking:
This job could trigger your main Pipeline job when changes are detected.

Here’s a rough untested example of how you could set up the separate job:

  1. Create a Pipeline job in Jenkins.
  2. In the job configuration, set up the SCM to point to the repository you want to poll.
  3. In the “Build Triggers” section, enable “Poll SCM” and set the schedule as needed.
  4. In the “post” section of your pipeline, add a build to your main Pipeline job.
pipeline {
    agent any
    stages {
        stage('Example') {
            steps {
                echo 'Hello World'
    post {
        always {
            build job: 'other-job', parameters: [string(name: 'Param', value: 'value')]

In your main Pipeline job, you could then remove the pollSCM trigger, as the new job will now be responsible for triggering it.

Well i already have two jobs:
Job1 = The job that’s supposed to poll the scm and execute job2 with paramters.
Job2 = Job to be executed reguarly.

Are you implying it’s not possible to do in a jenkinsfile but somehow when using the UI? Also i would rather not do that since it will have to clone the whole repo for a job that isn’t doing much and i would have to setup multiple times probably also.

1 Like

The git checkout step allows to configure the given repository to be included in the polling, at least the snippet generator provides a checkbox for this. Of course this can only work when the step is in the same pipeline. You can have multiple checkout steps in one job so you can potentially poll for multiple repos.

To avoid a full clone you could work with git ls-remote repo. You will need to persist the git hash you get yourself (so you need a fixed workspace, if the job can run on different agents that would not work out of the box) and then compare if something has changed and then trigger a build.

I do this myself ( the repo is over 10GiB and a clone takes about 1h and a simple fetch 2-3 minutes) and store the file with the last git hash on an nfs share. But the ls-remote check takes a second or so.

This is my poller job:

propFile = "/somenfs_mount/POLLER_job_for_<branch>/commit.prop"
triggerBuilds = false
node('pollerhost') {
    def d = [COMMIT: 'no build']
    props = readProperties defaults: d, file: propFile
    last_build_commit = props['COMMIT']
    echo("Last build commit was $last_build_commit")
    sshagent(['mycred']) {
        ls_remote = sh label: '', returnStdout: true, script: 'git ls-remote --heads ssh:// git refs/heads/<branch>'
    current_commit = ls_remote.split()[0]
    echo("Current commit of <branch> is $current_commit")
    if (last_build_commit != current_commit)
        echo("new content found, trigger build")
        writeFile file: propFile, text: "COMMIT=$current_commit"
        triggerBuilds = true
    } else {
        echo("no new content found, no build necessary")

if (triggerBuilds) {
    build job: 'otherjob', parameters: [string(name: 'COMMIT', value: current_commit)], propagate: false

Oh yeah this works with some minor changes. Thanks