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

NPE when getting upstreambuild after starting a rebuild

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major Major
    • build-user-vars-plugin
    • None
    • Plugin v1.3

      Precondition:

      • install rebuild plugin
      • create a Job A that triggers a Job B
      • Job A has a log rotation set to "keep 2 builds", Job B has no log rotation set
      • run Job A several times (let say 5 times)

      Actual:
      Job A - history: build 4 and build 5
      Job B - history: build 1,2,3,4 and 5

      Action:
      Select Job B build 2 and run "rebuild" via "rebuild plugin"

      Currently:
      java.lang.NullPointerException
      at org.jenkinsci.plugins.builduser.BuildUser.makeUserBuildVariables(BuildUser.java:73)
      at org.jenkinsci.plugins.builduser.BuildUser.makeUserBuildVariables(BuildUser.java:77)
      at org.jenkinsci.plugins.builduser.BuildUser.makeBuildVariables(BuildUser.java:64)
      at hudson.model.AbstractBuild.getBuildVariables(AbstractBuild.java:984)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)

      Problem:
      org.jenkinsci.plugins.builduser.BuildUser.makeUserBuildVariables(Run build, Map<String, String> variables)

       
              // If build has been triggered form an upstream build, get UserCause from there to set user build variables
              Cause.UpstreamCause upstreamCause = (Cause.UpstreamCause) build.getCause(Cause.UpstreamCause.class);
              if (upstreamCause != null) {
                  Job job = Jenkins.getInstance().getItemByFullName(upstreamCause.getUpstreamProject(), Job.class);
                  Run upstream = job.getBuildByNumber(upstreamCause.getUpstreamBuild());
                  makeUserBuildVariables(upstream, variables);
              }
      

      The problem is that the upstreamCause is checked for null, but in case of logrotation (or maybe also an manual delete) has deleted the upstream-run - the variable "upstream" is not checked to null. That leads to a recursive-call where method-argument "build" is null which is also not checked.

      Suggestion:
      either return on "build == null"
      or check Run upstream = job.getBuildByNumber(upstreamCause.getUpstreamBuild()); for null too

            Unassigned Unassigned
            zioschild Sven Appenrodt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: