How to create an influxdb target for jenkins pipeline project?

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      Jenkins pipeline 2.150.2 
      InfluxDB 1.6.2

      I want to create a influx db target from jenkins pipeline project. I went through the document mentioned at https://wiki.jenkins.io/display/JENKINS/InfluxDB+Plugin

      Steps:

      1. Created a pipeline project

      2. In the pipeline block, I have below code as per the help doc

       

       def influxdb = Jenkins.instance.getDescriptorByType(jenkinsci.plugins.influxdb.DescriptorImpl)
       
      // Create target
      def target = new jenkinsci.plugins.influxdb.models.Target()
       
      // Set target details
      // Mandatory fields
      target.description = 'jenkins_data'
      target.url = 'http://127.0.0.1:8086'
      target.username = 'admin'
      target.password = ''
      target.database = 'jenkins_data'
      // Optional fields
      target.exposeExceptions = true // default = true
      target.jobScheduledTimeAsPointsTimestamp = true // default = false
      target.usingJenkinsProxy = true // default = false
      target.retentionPolicy = 'autogen' // default = 'autogen'
      // NEW in version 1.20.1
      //target.replaceDashWithUnderscore = true // default = false
       
      // Add a target by using the created target object
      influxdb.addTarget(target)
      influxdb.save()
       
      // Write stuff to InfluxDB
      // NOTE! If you have more targets configured in Jenkins, it's safer to add "selectedTarget" parameter to the InfluxDB step to ensure
      // data is sent to the correct target.
      // step([$class: 'InfluxDbPublisher', target: 'myNewTarget', selectedTarget: 'myNewTarget', customPrefix: 'myPrefix', customData: myDataMap])
      def myDataMap = [:]
      myDataMap['myKey'] = 'myValue' 
      step([$class: 'InfluxDbPublisher', target: 'jenkins_data', selectedTarget: 'jenkins_data', customPrefix: 'myPrefix', customData: myDataMap])
      // Remove a target by using the target description field value
      influxdb.removeTarget("jenkins_data")
      influxdb.save()
      println "saved"
      

       

       

      3. Build the project and I see below error in console output

      Console output: 

      org.jenkinsci.plugins.workflow.steps.MissingContextVariableException: Required context class hudson.FilePath is missing
      Perhaps you forgot to surround the code with a step that provides this, such as: node
       at org.jenkinsci.plugins.workflow.steps.StepDescriptor.checkContextAvailability(StepDescriptor.java:261)
       at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:260)
       at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:176)

       

      Any suggestions would be really helpful?

            Assignee:
            Aleksi Simell
            Reporter:
            sridatta s
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: