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

NullPointerException when using InfluxDB Plugin in Pipeline script

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Component/s: influxdb-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.32.1
      InfluxDB Plugin 1.10.1
    • Similar Issues:

      Description

      When invoking InfluxDB Plugin in a Pipeline script, it will throw java.lang.NullPointerException since the build has not finished and hudson.model.Run.getResult() will return null. This exception (unless caught) makes the build fail.

      Step:

      step([$class: 'InfluxDbPublisher',
      	  customData: null, customDataMap: null, customPrefix: null
      	  customPrefix: "<REDACTED>",
      	  target: "<REDACTED>"])
      

      Build output:

      [InfluxDB Plugin] Publishing data to: [url=<REDACTED>, description=<REDACTED> username=<REDACTED>, password=*****, database=<REDACTED>]
      ...
      java.lang.NullPointerException
      	at jenkinsci.plugins.influxdb.generators.JenkinsBasePointGenerator.generate(JenkinsBasePointGenerator.java:54)
      	at jenkinsci.plugins.influxdb.InfluxDbPublisher.perform(InfluxDbPublisher.java:203)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
      	at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:59)
      	at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:47)
      	at hudson.security.ACL.impersonate(ACL.java:221)
      	at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:44)
      	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      	at java.lang.Thread.run(Thread.java:745)
      Finished: FAILURE
      

      Related line in InfluxDB Code: https://github.com/jenkinsci/influxdb-plugin/blob/1.10.1/src/main/java/jenkinsci/plugins/influxdb/generators/JenkinsBasePointGenerator.java#L54

      Related documentation for Jenkins API:
      http://javadoc.jenkins.io/hudson/model/Run.html#getResult()

      Workaround:

      try {
          // Build things here
          if(currentBuild.result == null) {
              currentBuild.result = "SUCCESS"
          }
      } catch (err) {
          if(currentBuild.result == null) {
              currentBuild.result = "FAILURE"
          }
          throw err
      } finally {
          step([$class: 'InfluxDbPublisher', ...
      }
      

        Attachments

          Activity

          Hide
          knepperjm John Knepper added a comment -

          Could you post an example of description based for the Jenkins InfluxDB configuration in the configure system section of Jenkins? Aleksi SimellThanks!

          Show
          knepperjm John Knepper added a comment - Could you post an example of description based for the Jenkins InfluxDB configuration in the configure system section of Jenkins? Aleksi Simell Thanks!
          Hide
          aleksisimell Aleksi Simell added a comment -

          John Knepper See my previous comment. Basically, when you configure InfluxDB Plugin in the global settings, you need to specify a description, URL, database, username, password, and retention policy. 

          Consider you had a description: "myDescription", URL: "http://127.0.0.1:8086", and database: "myDatabase".

          Until 1.10.3, the pipeline script needed to be configured 

          step([$class: 'InfluxDbPublisher', target: 'http://127.0.0.1:8086,myDatabase', ...])

          But now (= in the next release) you can specify

          step([$class: 'InfluxDbPublisher', target: 'myDescription', ...])
          

          which is a lot easier (provided that the description is not overly long). I hope that clarifies the change.

           

          Show
          aleksisimell Aleksi Simell added a comment - John Knepper See my previous comment. Basically, when you configure InfluxDB Plugin in the global settings, you need to specify a description, URL, database, username, password, and retention policy.  Consider you had a description: "myDescription", URL: "http://127.0.0.1:8086", and database: "myDatabase". Until 1.10.3, the pipeline script needed to be configured  step([$class: 'InfluxDbPublisher' , target: 'http: //127.0.0.1:8086,myDatabase' , ...]) But now (= in the next release) you can specify step([$class: 'InfluxDbPublisher' , target: 'myDescription' , ...]) which is a lot easier (provided that the description is not overly long). I hope that clarifies the change.  
          Hide
          knepperjm John Knepper added a comment -

          Aleksi Simell I apologize I do not have much familiarity with this pipeline.  This is what I have:

           

          Show
          knepperjm John Knepper added a comment - Aleksi Simell I apologize I do not have much familiarity with this pipeline.  This is what I have:  
          Hide
          aleksisimell Aleksi Simell added a comment -

          That configuration looks fine. When you write a pipeline script, you need to specify target as 

          step([$class: 'InfluxDbPublisher', target: 'http://influxdb-develop.demandbase.com:8086,jenkins_db',...])

           

          Show
          aleksisimell Aleksi Simell added a comment - That configuration looks fine. When you write a pipeline script, you need to specify target as  step([$class: 'InfluxDbPublisher' , target: 'http: //influxdb-develop.demandbase.com:8086,jenkins_db' ,...])  
          Hide
          aleksisimell Aleksi Simell added a comment -

          Since there has been no activity regarding this issue, I will close this again as fixed.

          Show
          aleksisimell Aleksi Simell added a comment - Since there has been no activity regarding this issue, I will close this again as fixed.

            People

            • Assignee:
              aleksisimell Aleksi Simell
              Reporter:
              cryptidvulpes Jami Lindh
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: