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

Only last stage data is sent to influx db from jenkins pipeline

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • influxdb-plugin, pipeline
    • None
    • Jenkins pipeline 2.150.2
      InfluxDB 1.6.2

      I have below code which reads each 'stage' data from a jenkins_pipeline project json output and sends each stage data to influxDB.

      Issue: It sends only last stage data to influx db but I noticed it iterating on each stages

       

      Any suggestions would be helpful.
      //Methods for InfluxData begins
      //Maps for Field type columns
       myDataField1 = [:]
       myDataField2 = [:]
       myDataField3 = [:]
      //Maps for Custom Field measurements
       myCustomDataFields1 = [:]
       myCustomDataFields2 = [:]
       myCustomDataFields3 = [:]
      //Maps for Tag type columns
       myDataTag1 = [:]
       myDataTag2 = [:]
       myDataTag3 = [:]
      //Maps for Custom Tag measurements
       myCustomDataTags1 = [:]
       myCustomDataTags2 = [:]
       myCustomDataTags3 = [:]
      @NonCPS
       def pushStageData() {
      def url_string = "${JENKINS_URL}job/ENO_ENG_TP/job/R421/13/wfapi/describe"
       def replaced = url_string.replaceAll(' ', '%20');
       get = null;
       def get = new URL(replaced).openConnection();
      get.addRequestProperty ("User-Agent","Mozilla/4.0"); 
       get.addRequestProperty("Authorization", "Basic dZXZvceDIwMTk=");
      //fetching the contents of the endpoint URL
       def jsonText = get.getInputStream().getText();
       //converting the text into JSON object using JsonSlurperClassic 
       def jsonObject = new JsonSlurperClassic().parseText(jsonText)
      // Extracting the details of all the stages present in that particular build number
       for (int i=0; i<jsonObject.stages.size()-1; i++){ //size-1 to ignore the post stage
       //populating the field type columns of InfluxDB measurements and pushing them to the map called myDataField1
       def size = jsonObject.stages.size()-1
       myDataField1['result'] = jsonObject.stages[i].status
       myDataField1['duration'] = jsonObject.stages[i].durationMillis
       myDataField1['stage_name'] = jsonObject.stages[i].name
      //populating the tag type columns of InfluxDB measurements and pushing them to the map called myDataTag1
       myDataTag1['result_tag'] = jsonObject.stages[i].status
       myDataTag1['stage_name_tag'] = jsonObject.stages[i].name
      //assigning field type columns to the measurement called CustomData
       myCustomDataFields1['CustomData'] = myDataField1
       //assigning tag type columns to the measurement called CustomData
       myCustomDataTags1['CustomData'] = myDataTag1
      //Push the data into influx instance
       try
      { step([$class: 'InfluxDbPublisher', target: 'jenkins_data', customPrefix: null, customDataMapTags: myCustomDataTags1]) }
      catch (err)
      { println ("pushStagData exception: " + err) }
      }
       }
      

       

            aleksisimell Aleksi Simell
            sridattasp sridatta s
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: