Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-41602

Global Shared Library git ref overrides the project repo git info

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Cannot Reproduce
    • Labels:
    • Environment:
      Jenkins 2.19.1(installed via apt)
      master and nodes (via ssh): ubuntu 14.04.5 LTS, openJDK 1.8.0_91

      bitbucket-build-status-notifier 1.3.1
      pipeline: shared groovy libraries 2.5
      pipeline remote loader 1.3
      git plugin 3.0.1
    • Similar Issues:

      Description

      My organization has been using Jenkins 2.0 and Pipelines for several months. We've reached a critical point where we need a global library to consolidate functionality and reduce configuration drift of our Jenkinsfiles and scripts. I created a git repo in our Bitbucket team to hold common functions, the first of which are notifications classes for sending build status to Hipchat and Bitbucket (e.g. src/com/team/notifications/Bitbucket.groovy):

      +package com.team.jenkins.notifications
      +
      +class Bitbucket implements Serializable {
      +
      +    def script
      +    Bitbucket(script) {
      +        this.script = script
      +    }
      +
      +    def started() {
      +        this.script.bitbucketStatusNotify (
      +            buildState: 'INPROGRESS'
      +        )
      +    }
      +
      +    def succeeded() {
      +        this.script.bitbucketStatusNotify (
      +            buildState: 'SUCCESSFUL'
      +        )
      +    }
      +
      +    def failed(stage, err) {
      +        this.script.bitbucketStatusNotify (
      +            buildState: 'FAILED',
      +            buildDescription: "Build failed during ${stage}: ${err}"
      +        )
      +    }
      +}
      

      Our development workflow depends on Jenkins build approvals of pull requests, using the Bitbucket build status notifier plugin. The above class "works", in that it sends build status notifications to bitbucket, but the problem is that it is always sending those notifications to the shared library repo, not the repo that is being built (e.g. one of our Java libraries or webapps).

      I have tested the above library as both a class and as a global var implementation, both explicitly and implicitly loaded into the pipeline script. I have also confirmed that the normal non-shared-library usage of the bitbucket-status-notifier plugin is affected by the shared library git repo, so the plugin can't be used at all, it seems, if there's a shared library brought into a pipeline job. Here's its usage as an explicit library:

      @Library('common-jenkins') import com.team.jenkins.notifications.Bitbucket
      def bitbucketer
      
      node() {
          stage('init) {
              git url: 'https://user@bitbucket.org/team/repo.git'
              bitbucketer = new Bitbucket(this)
              sh './gradlew clean'
              bitbucketer.started()
          }
      
          stage('build') {
              try {
                  sh './gradlew build'
              } catch (Exception e) {
                  bitbucketer.failed('build', e)
              }
              bitbucketer.succeeded()
          }
      }
      

      As has already been reported on JENKINS-40150 and JENKINS-41442, the git repo information of the shared library is bleeding into the execution of the pipeline job. We have other pipeline operations that reference Git info, so I am unable to expand actual usage of the shared library to our other projects, with this interference.

        Attachments

          Activity

          Hide
          therefromhere1 John Carter added a comment -

          We are seeing this issue.

           

          Jenkins 2.88

          Bitbucket Branch Source 2.2.3

          Pipeline 2.5

          Pipeline: Shared Groovy Libraries 2.9

          Pipeline: Multibranch 2.16

           

           global library is set up in Jenkins -> "Configure System" as a "Global Pipeline Library", with "Load Implicitly" off, " Include @Library changes in job recent changes" off.

          Show
          therefromhere1 John Carter added a comment - We are seeing this issue.   Jenkins 2.88 Bitbucket Branch Source 2.2.3 Pipeline 2.5 Pipeline: Shared Groovy Libraries 2.9 Pipeline: Multibranch 2.16    global library is set up in Jenkins -> "Configure System" as a "Global Pipeline Library", with "Load Implicitly" off, " Include @Library changes in job recent changes" off.
          Hide
          thomastardy Thomas Tardy added a comment -

          +1

          We are having the same issue as John Carter in Jenkins 2.90. When I add the global library, the git repo info is changed to the one of the shared library.

          Show
          thomastardy Thomas Tardy added a comment - +1 We are having the same issue as John Carter in Jenkins 2.90. When I add the global library, the git repo info is changed to the one of the shared library.
          Hide
          macha762 Maxime Charron added a comment -

          +1 

          We are also having the same issue as John and Thomas. Antonio Mansilla could you reopen this and try to reproduce?

          Show
          macha762 Maxime Charron added a comment - +1  We are also having the same issue as John and Thomas. Antonio Mansilla could you reopen this and try to reproduce?
          Hide
          macha762 Maxime Charron added a comment -

          Antonio Mansilla or you could look at this PR which provides a nice workaround

          Show
          macha762 Maxime Charron added a comment - Antonio Mansilla or you could look at this PR  which provides a nice workaround
          Hide
          rohitsrmuniv Rohit Kumar added a comment -

          Have the same issue with Jenkins version 2.134, even passing the optional parameter for commit overrides with the shared library one. 

           
          bitbucketStatusNotify(
          buildState: 'SUCCESSFUL',
          commitId: 'xxxxxxxxx' )

          Show
          rohitsrmuniv Rohit Kumar added a comment - Have the same issue with Jenkins version 2.134, even passing the optional parameter for commit overrides with the shared library one.    bitbucketStatusNotify( buildState: 'SUCCESSFUL', commitId: 'xxxxxxxxx' )

            People

            Assignee:
            flagbit Antonio Mansilla
            Reporter:
            amundsenjunior Scott Russell
            Votes:
            3 Vote for this issue
            Watchers:
            9 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: