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

currentBuild.getBuildCauses(type) fails when type is a cause contributed by a plugin

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved (View Workflow)
    • Major
    • Resolution: Fixed
    • None
    • Jenkins ver. 2.138.3
      workflow support 2.22
      all latest plugin uploads as of issue creation
    • workflow-support 2.24

    Description

      currentBuild.getBuildCauses(type) was added in 2.22 which seems to work for Jenkins built-in causes but fails when trying to look-up causes contributed by plugins.

      Example - replay after building first time with failure to see echo'd output shown below:

      echo "${currentBuild.buildCauses}"
      currentBuild.getBuildCauses('org.jenkinsci.plugins.workflow.cps.replay.ReplayCause')
      

      Fails with: 

      [Pipeline] echo
      [[_class:hudson.model.Cause$UserIdCause, shortDescription:Started by user anonymous, userId:null, userName:anonymous], [_class:org.jenkinsci.plugins.workflow.cps.replay.ReplayCause, shortDescription:Replayed #9]]
      [Pipeline] End of Pipeline
      java.lang.ClassNotFoundException: org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
      	at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1374)
      	at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1327)
      	at jenkins.util.AntClassLoader.loadClass(AntClassLoader.java:1080)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      	at java.lang.Class.forName0(Native Method)
      	at java.lang.Class.forName(Class.java:264)
      	at org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getBuildCauses(RunWrapper.java:152)
              ...

       My presumption is that it is not using the correct classloader.

      Attachments

        Activity

          mkobit Mike Kobit created issue -
          mkobit Mike Kobit made changes -
          Field Original Value New Value
          Description {{currentBuild.getBuildCauses(type)}} was added in 2.22 which seems to work for Jenkins built-in causes but fails when trying to look-up causes contributed by plugins.

          Example:
          {code:java}
          currentBuild.getBuildCauses('org.jenkinsci.plugins.workflow.cps.replay.ReplayCause')
          {code}
          Fails with: 
          {noformat}
          java.lang.ClassNotFoundException: org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
          at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1374)
          at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1327)
          at jenkins.util.AntClassLoader.loadClass(AntClassLoader.java:1080)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:264)
          at org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getBuildCauses(RunWrapper.java:152)
                  ...{noformat}
           My presumption is that it is not using the correct classloader.
          {{currentBuild.getBuildCauses(type)}} was added in 2.22 which seems to work for Jenkins built-in causes but fails when trying to look-up causes contributed by plugins.

          Example - replay after building first time with failure to see echo'd output shown below:
          {code:java}
          echo "${currentBuild.buildCauses}"
          currentBuild.getBuildCauses('org.jenkinsci.plugins.workflow.cps.replay.ReplayCause')
          {code}
          Fails with: 
          {noformat}
          [Pipeline] echo
          [[_class:hudson.model.Cause$UserIdCause, shortDescription:Started by user anonymous, userId:null, userName:anonymous], [_class:org.jenkinsci.plugins.workflow.cps.replay.ReplayCause, shortDescription:Replayed #9]]
          [Pipeline] End of Pipeline
          java.lang.ClassNotFoundException: org.jenkinsci.plugins.workflow.cps.replay.ReplayCause
          at jenkins.util.AntClassLoader.findClassInComponents(AntClassLoader.java:1374)
          at jenkins.util.AntClassLoader.findClass(AntClassLoader.java:1327)
          at jenkins.util.AntClassLoader.loadClass(AntClassLoader.java:1080)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:264)
          at org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper.getBuildCauses(RunWrapper.java:152)
                  ...{noformat}
           My presumption is that it is not using the correct classloader.
          dnusbaum Devin Nusbaum made changes -
          Released As workflow-support 2.24
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Resolved [ 5 ]
          dnusbaum Devin Nusbaum made changes -
          Remote Link This issue links to "jenkinsci/workflow-support-plugin#85 (Web Link)" [ 22513 ]

          People

            Unassigned Unassigned
            mkobit Mike Kobit
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: