Jenkins trigger build if shared library changes I have Jenkins Pipeline job define in my git repo as.

// File: deployment/jenkinsfiles/staging/Merge

@Library("my_shared_lib") _

import com.company.myteam.Constants

pipeline {
    agent { label "common" }

    triggers {
        pollSCM("H/2 * * * *")
    }

    options {
        buildDiscarder(logRotator(numToKeepStr: "50", artifactNumToKeepStr: "50"))
    }

    stages {
        stage ("Staging Merge") {
            steps {
                script {
                    def config = new Constants().repoconfig
                    ansiColor("xterm") {
                        myteam.pipelines.stagingMerge(config)
                    }
                }
            }
        }
    }
    post {
        always {
            cleanWs()
        }
    }
}


Then I created jenkins job configuration as below.



Now, When I check the Git Polling Log its polling shared-library too.

Started on Feb 25, 2020 5:33:07 PM
Using strategy: Default
[poll] Last Built Revision: Revision 681f996e689bdeb9cfca2b167002b8ccd99590cb (origin/staging)
using credential github_username_with_token
 &gt; git --version # timeout=10
using GIT_ASKPASS to set credentials Github Service Account Username with token
 &gt; git ls-remote -h https://myuser@github.company.com/myteam/myrepo # timeout=10
Found 6 remote heads on https://myuser@github.company.com/myteam/myrepo
[poll] Latest remote head revision on refs/heads/staging is: 681f996e689bdeb9cfca2b167002b8ccd99590cb - already built by 53
Using strategy: Default
[poll] Last Built Revision: Revision e80628ec7c9dbc59decbc81a3b884dcaa963a8dc (refs/remotes/origin/master)
using credential github_username_with_token
 &gt; git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repositories
 &gt; git config remote.origin.url https://myuser@github.company.com/myteam/jenkins-shared-libraries.git # timeout=10
Fetching upstream changes from https://myuser@github.company.com/myteam/jenkins-shared-libraries.git
 &gt; git --version # timeout=10
using GIT_ASKPASS to set credentials Github Service Account Username with token
 &gt; git fetch --tags --progress https://myuser@github.company.com/myteam/jenkins-shared-libraries.git +refs/heads/*:refs/remotes/origin/* # timeout=10
Polling for changes in
 &gt; git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 &gt; git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
 &gt; git log --full-history --no-abbrev --format=raw -M -m --raw e80628ec7c9dbc59decbc81a3b884dcaa963a8dc..869b3a16e07d21a88d557f1857376bfed7717a6e # timeout=10


Whenever I change code in jenkins-shared-library, its start build for the job.

I tried workaround given in https://issues.jenkins.io/browse/JENKINS-39615?focusedCommentId=280729&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-280729, but no luck.

I changed my pollSCM to githubPush, but this also trigger when I change in shared-library. 

I tried solution given in https://issues.jenkins-ci.org/browse/JENKINS-41497 as Ignore on push notifications for githubPush() but still its triggering job.

Before moving to pipeline, I had freestyle project. Where there is section Source Code Management, where we can define the branch, and githubPush() was listening on that branch only. 

 

When we select project type as pipeline there is no Source code management section. May be due to that, its listening for all push events.

By push or poll, I want to restrict my jenkins job to trigger only when there is changes on myrepo.git only.
This issue can be solved by using legacy SCM option. Go to Jenkins -&gt; Manage Jenkins -&gt; Configure System and select &quot;Legacy SCM&quot; option for share libs. this will resolve the issue completely, It worked for us.