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

manager.setBuildNumber() does not seem to do anything

      Simple Jenkinsfile:

       

      if (manager.setBuildNumber(1)) {
        echo "Current build: ${manager.build.number}"
        manager.createSummary("gear2.gif").appendText("<h2>Testing</h2>", false)
      }
      

       

      Output:

      [Pipeline] echo
      Current build: 3
      [Pipeline] End of Pipeline

      3 is the current build number so this number changes on every build and the createSummary() is added to the current build instead of build number 1 (not what I expect).

      Expected behaviour is to see build number 1 being set and the summary being added to build number 1.

          [JENKINS-43012] manager.setBuildNumber() does not seem to do anything

          Gonzalo Servat added a comment - - edited

          setBuildNumber() is returning true, which means the call to:

          Run<?, ?> newBuild = build.getParent().getBuildByNumber(buildNumber);
          

          ... returned not null. So it looks like getBuildByNumber() is returning the current build regardless of the buildNumber specified.

           

          Also, I think this might be related to us using the multibranch plugin.

          Gonzalo Servat added a comment - - edited setBuildNumber() is returning true, which means the call to: Run<?, ?> newBuild = build.getParent().getBuildByNumber(buildNumber); ... returned not null. So it looks like getBuildByNumber() is returning the current build regardless of the buildNumber specified.   Also, I think this might be related to us using the multibranch plugin.

          James Chuong added a comment -

          Issue exists in Jenkins 2.121.3 LTS with groovy-postbuild-plugin 2.4.2

          Workaround I have done is to just rewrite the parts I actually want as a Jenkins global shared library.  I just avoid using manager and directly interact with the build.  Since it is a globally loaded library, it also avoids the security sandboxing.

          vars/foo.groovy
          
          import com.jenkinsci.plugins.badge.action.BadgeAction;
          @NonCPS
          def addBadge(jobName, buildNumber) {
            def project = manager.hudson.getItemByFullName(jobName)
            def build = project.getBuildByNumber(buildNumber as Integer)
            build.addAction(BadgeAction.createBadge(icon, text, link));
          } 

          James Chuong added a comment - Issue exists in Jenkins 2.121.3 LTS with groovy-postbuild-plugin 2.4.2 Workaround I have done is to just rewrite the parts I actually want as a Jenkins global shared library.  I just avoid using manager and directly interact with the build.  Since it is a globally loaded library, it also avoids the security sandboxing. vars/foo.groovy import com.jenkinsci.plugins.badge.action.BadgeAction; @NonCPS def addBadge(jobName, buildNumber) { def project = manager.hudson.getItemByFullName(jobName) def build = project.getBuildByNumber(buildNumber as Integer ) build.addAction(BadgeAction.createBadge(icon, text, link)); }

            wolfs Stefan Wolf
            gservat Gonzalo Servat
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: