Answers: <p>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.</p>
  <p><a href="https://i.sstatic.net/LFjy5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LFjy5.png" alt="enter image description here" /></a></p>
  
Answers: CC BY-SA 4.0
Answers: 2022-10-07T13:06:53.463Z
Answers: I've tried the options from Ievgen's answer first, but this is the only solution that worked for me.
Answers: not2savvy
Answers: CC BY-SA 4.0
Answers: 2020-12-17T10:31:57.533Z
Answers: 2020-12-17T10:31:57.533Z
Answers: nilesh1212
Answers: <p>Do I understand correctly that you don't want changes in the shared library to trigger builds for your project/pipeline?</p>
  <p>If so, you can do it per-pipeline by modifying the <code>@Library(&quot;my_shared_lib&quot;) _</code> statement to include <code>changelog=false</code> parameter, like so <code>@Library(&quot;my_shared_lib&quot;, changelog=false) _</code>.</p>
  <p>You can also do that globally, for a specific library - uncheck the <code>Include @Library changes in job recent changes</code> checkbox (in global Jenkins configuration).</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-07-27T13:48:39.000Z
Answers: I tried that option it was not working for me.
Answers: nilesh1212
Answers: CC BY-SA 4.0
Answers: 2022-10-07T13:05:12.047Z
Answers: Although this seems to be the correct solution as described in the docs, it didn't work for me either.
Answers: not2savvy
Answers: CC BY-SA 4.0
Answers: 2021-01-19T21:10:31.513Z
Answers: 2021-01-19T21:10:31.513Z
Answers: Ievgen Popovych
Body: <p>I have Jenkins <code>Pipeline</code> job define in my git repo as.</p>
  
  <pre><code>// 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()
          }
      }
  }
  </code></pre>
  
  <p>Then I created jenkins job configuration as below.</p>
  
  <p><a href="https://i.sstatic.net/ns4bB.png" rel="noreferrer"><img src="https://i.sstatic.net/ns4bB.png" alt="Jenkins Job Config"></a></p>
  
  <p>Now, When I check the <code>Git Polling Log</code> its polling <code>shared-library</code> too.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Whenever I change code in <code>jenkins-shared-library</code>, its start build for the job.</p>
  
  <p>I tried <code>workaround</code> given in <a href="https://issues.jenkins.io/browse/JENKINS-39615?focusedCommentId=280729&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-280729" rel="noreferrer">https://issues.jenkins.io/browse/JENKINS-39615?focusedCommentId=280729&amp;page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-280729</a>, but no luck.</p>
  
  <p>I changed my <code>pollSCM</code> to <code>githubPush</code>, but this also trigger when I change in <code>shared-library</code>. </p>
  
  <p>I tried solution given in <a href="https://issues.jenkins-ci.org/browse/JENKINS-41497" rel="noreferrer">https://issues.jenkins-ci.org/browse/JENKINS-41497</a> as <code>Ignore on push notifications</code> for <code>githubPush()</code> but still its triggering job.</p>
  
  <p>Before moving to <code>pipeline</code>, I had <code>freestyle</code> project. Where there is section <strong>Source Code Management</strong>, where we can define the branch, and <code>githubPush()</code> was listening on that branch only. </p>
  
  <p><a href="https://i.sstatic.net/vKeww.png" rel="noreferrer"><img src="https://i.sstatic.net/vKeww.png" alt="Source Code Management"></a> </p>
  
  <p>When we select project type as <code>pipeline</code> there is no <strong>Source code management</strong> section. May be due to that, its listening for all push events.</p>
  
  <p>By <code>push</code> or <code>poll</code>, I want to restrict my jenkins job to trigger only when there is changes on <code>myrepo.git</code> only.</p>
  
Comments: CC BY-SA 4.0
Comments: 2020-03-10T16:01:52.183Z
Comments: Is there a reason you’re not using Webhooks to trigger the Jenkins Build?
Comments: Julian Veerkamp
Comments: CC BY-SA 4.0
Comments: 2020-03-12T01:16:03.933Z
Comments: I tried webhook too, but it send event when I update my shared library too
Comments: Nilesh
Comments: CC BY-SA 4.0
Comments: 2020-03-13T12:02:56.467Z
Comments: That is weird, The webhook should only trigger for the Repo that it was configured for.
Comments: Julian Veerkamp
Comments: CC BY-SA 4.0
Comments: 2020-03-13T12:59:44.237Z
Comments: yes, but that is happening if you have "Source Code Management" section, if you create pipeline, this section is not there. Did you tried on `pipeline` type of project ?
Comments: Nilesh
Comments: CC BY-SA 4.0
Comments: 2020-03-13T16:34:48.237Z
Comments: I'm using Webhooks in combination with Multibranch Pipelines. I've configured my git repo to trigger a webhook on every push to run just this project. Polling should then only happen on a push to the project repo.
Comments: Julian Veerkamp
Tags: <jenkins><jenkins-pipeline><git><git-hooks>
Title: Jenkins trigger build if shared library changes
UserDisplayName: Nilesh
ThreadText: # Jenkins trigger build if shared library changes
  
  (Asked by: username_0 on 2020-02-25)
  
  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.
  
  [![Jenkins Job Config](https://i.sstatic.net/ns4bB.png)](https://i.sstatic.net/ns4bB.png)
  
  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
   > git --version # timeout=10
  using GIT_ASKPASS to set credentials Github Service Account Username with token
   > 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
   > git rev-parse --is-inside-work-tree # timeout=10
  Fetching changes from the remote Git repositories
   > 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
   > git --version # timeout=10
  using GIT_ASKPASS to set credentials Github Service Account Username with token
   > 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
   > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
   > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
   > 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&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.
  
  [![Source Code Management](https://i.sstatic.net/vKeww.png)](https://i.sstatic.net/vKeww.png)
  
  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.
  
  **Tags:** jenkins, jenkins-pipeline, git, git-hooks
  
  > **Comments:**
  > **username_1**: Is there a reason you’re not using Webhooks to trigger the Jenkins Build?  
  > **username_0**: I tried webhook too, but it send event when I update my shared library too  
  > **username_1**: That is weird, The webhook should only trigger for the Repo that it was configured for.  
  > **username_0**: yes, but that is happening if you have "Source Code Management" section, if you create pipeline, this section is not there. Did you tried on `pipeline` type of project ?  
  > **username_1**: I'm using Webhooks in combination with Multibranch Pipelines. I've configured my git repo to trigger a webhook on every push to run just this project. Polling should then only happen on a push to the project repo.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2020-12-17. Score: 4
  
  This issue can be solved by using legacy SCM option. Go to Jenkins -> Manage Jenkins -> Configure System and select "Legacy SCM" option for share libs. this will resolve the issue completely, It worked for us.
  
  [![enter image description here](https://i.sstatic.net/LFjy5.png)](https://i.sstatic.net/LFjy5.png)
  
  > **Comments:**
  > **username_3**: I've tried the options from username_4's answer first, but this is the only solution that worked for me.  
  
  ---
  
  ### Answer by username_4 on 2021-01-19. Score: 1
  
  Do I understand correctly that you don't want changes in the shared library to trigger builds for your project/pipeline?
  
  If so, you can do it per-pipeline by modifying the `@Library("my_shared_lib") _` statement to include `changelog=false` parameter, like so `@Library("my_shared_lib", changelog=false) _`.
  
  You can also do that globally, for a specific library - uncheck the `Include @Library changes in job recent changes` checkbox (in global Jenkins configuration).
  
  > **Comments:**
  > **username_2**: I tried that option it was not working for me.  
  > **username_3**: Although this seems to be the correct solution as described in the docs, it didn't work for me either.  
  
  ---
  
  