HiveBrain v1.2.0
Get Started
← Back to all entries
patterngitMinor

Jenkins trigger build if shared library changes

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
triggersharedjenkinschangeslibrarybuild

Problem

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
> 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 # t

Solution

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.

Context

StackExchange DevOps Q#10904, answer score: 4

Revisions (0)

No revisions yet.