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

Using a specific global library version in consumers sometimes causes notifications of build success/failure on the library that they consume

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • None
    • bitbucket server 4.13.0
      bitbucket branch source 2.0.2
      git plugin 3.0.4

      It looks like other Bitbucket Branch Source folders that consume a global library in Bitbucket, it also notifies that commit of that repository of failure or success (sometimes?).

      Jenkinsfile

      @Library('myLibrary@0.1.0')
      
      node {
        sh 'exit 1'
      }
      
      

      that is a contrived example, but see the attached image for multiple notifications that don't stem from this repository that seem to come from other consuming organization folder jobs.

          [JENKINS-41996] Using a specific global library version in consumers sometimes causes notifications of build success/failure on the library that they consume

          Mike Kobit added a comment -

          My first guess with very little amount of plugin development knowledge but looking at the source code https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotifications.java#L98 seems to only return a single action associated with the build, not multiple.

          Mike Kobit added a comment - My first guess with very little amount of plugin development knowledge but looking at the source code https://github.com/jenkinsci/bitbucket-branch-source-plugin/blob/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotifications.java#L98 seems to only return a single action associated with the build, not multiple.

          Mike Kobit added a comment -

          Any suggestions as to how to fix this? We are seeing this pop up more and more where unrelated build failures in consuming Bitbucket Branch Source projects are notifying failures on the global libraries, which is all stored in the same Bitbucket Server.

          Mike Kobit added a comment - Any suggestions as to how to fix this? We are seeing this pop up more and more where unrelated build failures in consuming Bitbucket Branch Source projects are notifying failures on the global libraries, which is all stored in the same Bitbucket Server.

          Mike Kobit added a comment -

          I ran the following in the script console for one of these builds that exhibited this behavior:

           

           

          import com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications
          import hudson.plugins.git.util.BuildData
          
          final jenkins = Jenkins.instance
          
          final coreOrg = jenkins.getAllItems(jenkins.branch.OrganizationFolder).find {
            it.displayName == 'CORE'
          }
          
          final translationService = coreOrg.getItem('translation-service')
          final master = translationService.getItem('master')
          
          final faultyBuild = master.getBuildByNumber(101)
          
          faultyBuild.getActions(BuildData).each {
            println(it)
          }
          
          println()
          

          And the results that came out were like this:

           

           

          hudson.plugins.git.util.BuildData@eb488be7[scmName=,remoteUrls=[ssh://git@internal-git.company.com:7999/jenkins/jenkins-pipeline-utilities.git],buildsByBranchName={0.4.0=Build #70 of Revision ec78141895c015cb891d625e95cb3a35145a81c7 (0.4.0), master=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)},lastBuild=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)]
          hudson.plugins.git.util.BuildData@ab0af0b6[scmName=,remoteUrls=[ssh://git@internal-git.company.com:7999/core/translation-service.git],buildsByBranchName={master=Build #101 of Revision b9560e970a46546e2186758e602a7e1ac420de03 (master)},lastBuild=Build #101 of Revision b9560e970a46546e2186758e602a7e1ac420de03 (master)]
          
          

          This seems like a bug in the place I mentioned above.

           

           

          If I change to:

          println(faultyBuild.getAction(BuildData))

          Then I get

          hudson.plugins.git.util.BuildData@eb488be7[scmName=,remoteUrls=[ssh://git@git.uptake.com:7999/blt/jenkins-pipeline-utilities.git],buildsByBranchName={0.4.0=Build #70 of Revision ec78141895c015cb891d625e95cb3a35145a81c7 (0.4.0), master=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)},lastBuild=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)]
          

          amuniz any advice on how I can fix this since I think I found the cause point would be appreciated. There are currently no tests for BitbucketBuildStatusNotifications so anything to help would be great.

          Mike Kobit added a comment - I ran the following in the script console for one of these builds that exhibited this behavior:     import com.cloudbees.jenkins.plugins.bitbucket.BitbucketBuildStatusNotifications import hudson.plugins.git.util.BuildData final jenkins = Jenkins.instance final coreOrg = jenkins.getAllItems(jenkins.branch.OrganizationFolder).find { it.displayName == 'CORE' } final translationService = coreOrg.getItem( 'translation-service' ) final master = translationService.getItem( 'master' ) final faultyBuild = master.getBuildByNumber(101) faultyBuild.getActions(BuildData).each { println(it) } println() And the results that came out were like this:     hudson.plugins.git.util.BuildData@eb488be7[scmName=,remoteUrls=[ssh: //git@internal-git.company.com:7999/jenkins/jenkins-pipeline-utilities.git],buildsByBranchName={0.4.0=Build #70 of Revision ec78141895c015cb891d625e95cb3a35145a81c7 (0.4.0), master=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)},lastBuild=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)] hudson.plugins.git.util.BuildData@ab0af0b6[scmName=,remoteUrls=[ssh: //git@internal-git.company.com:7999/core/translation-service.git],buildsByBranchName={master=Build #101 of Revision b9560e970a46546e2186758e602a7e1ac420de03 (master)},lastBuild=Build #101 of Revision b9560e970a46546e2186758e602a7e1ac420de03 (master)] This seems like a bug in the place I mentioned above.     If I change to: println(faultyBuild.getAction(BuildData)) Then I get hudson.plugins.git.util.BuildData@eb488be7[scmName=,remoteUrls=[ssh: //git@git.uptake.com:7999/blt/jenkins-pipeline-utilities.git],buildsByBranchName={0.4.0=Build #70 of Revision ec78141895c015cb891d625e95cb3a35145a81c7 (0.4.0), master=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)},lastBuild=Build #101 of Revision 9013619e45591ee4b8b4f3e411e0e810af30e5a2 (master)] amuniz any advice on how I can fix this since I think I found the cause point would be appreciated. There are currently no tests for BitbucketBuildStatusNotifications so anything to help would be great.

          Mike Kobit added a comment -

          This also sometimes causes no build notifications on Bitbucket Server because it has notified the incorrect commit.

          Mike Kobit added a comment - This also sometimes causes no build notifications on Bitbucket Server because it has notified the incorrect commit.

          Mike Kobit added a comment -

          Would something like the following work for replacing that method? This seems like it may work for Git, but not for Mercurial based libraries. Any support would be greatly appreciated.

          @CheckForNull
          private static String extractRevision(Run<?, ?> build) {
              String revision = null;
              SCMRevision scmRevision = SCMRevisionAction.getRevision(build);
              if (scmRevision != null) {
                  if (scmRevision instanceof AbstractGitSCMSource.SCMRevisionImpl) {
                      revision = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash();
                  }
              } else {
                  MercurialTagAction action = build.getAction(MercurialTagAction.class);
                  if (action != null) {
                      revision = action.getId();
                  }
              }
              return revision;
          }
          

          Mike Kobit added a comment - Would something like the following work for replacing that method? This seems like it may work for Git, but not for Mercurial based libraries. Any support would be greatly appreciated. @CheckForNull private static String extractRevision(Run<?, ?> build) { String revision = null ; SCMRevision scmRevision = SCMRevisionAction.getRevision(build); if (scmRevision != null ) { if (scmRevision instanceof AbstractGitSCMSource.SCMRevisionImpl) { revision = ((AbstractGitSCMSource.SCMRevisionImpl) scmRevision).getHash(); } } else { MercurialTagAction action = build.getAction(MercurialTagAction.class); if (action != null ) { revision = action.getId(); } } return revision; }

          Mike Kobit added a comment -

          I believe this was fixed by stephenconnolly

          Mike Kobit added a comment - I believe this was fixed by stephenconnolly

          Stephen Connolly added a comment - https://github.com/jenkinsci/bitbucket-branch-source-plugin/blame/master/src/main/java/com/cloudbees/jenkins/plugins/bitbucket/BitbucketBuildStatusNotifications.java#L103 should have fixed it IIUC

          Believed fixed as a side effect of JENKINS-43507

          Stephen Connolly added a comment - Believed fixed as a side effect of JENKINS-43507

          Using branch source plugin version 2.11. I still can see this issue - at least it really looks like this issue. Can you confirm that it is still fixed?

          Joerg Schwaerzler added a comment - Using branch source plugin version 2.11. I still can see this issue - at least it really looks like this issue. Can you confirm that it is still fixed?

          benoit guerin added a comment -

          Using version 2.2.12, I still see this issue too.

          Both my pipeline librairies, configured as global with implicit load, and the repository being built are notified of build status.

          benoit guerin added a comment - Using version 2.2.12, I still see this issue too. Both my pipeline librairies, configured as global with implicit load, and the repository being built are notified of build status.

            amuniz Antonio Muñiz
            mkobit Mike Kobit
            Votes:
            3 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: