• Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • influxdb-plugin
    • None

      I want to add custom fields to my global listener measurement for a build.

      As I understand from the Global Listener Documentation, I have the option to set the environment variables 

      INFLUXDB_PLUGIN_CUSTOM_FIELDS
      INFLUXDB_PLUGIN_CUSTOM_TAGS 

      The note states

       

      "The environment variables must be set on the final build object. If you are creating or updating these variables in a pipeline, you should make sure they are exported with an EnvironmentContributingAction."

      I tried setting the variables in the pipeline environment, for example

       

      pipeline {
        environment {
          INFLUXDB_PLUGIN_CUSTOM_FIELDS = "foo=bar"
        }
        ...
      } 

      but the data doesn't appear in my InfluxDB measurement.

       

      I took a look into the code but I can't find a mistake there. What is the correct way to set the environment variable on the "final build object"? Could you please give an example for that?

      Cheers!

       

      Update

      I even set the environment variable INFLUXDB_PLUGIN_CUSTOM_FIELDS globally for my build agent but it still isn't added to the measurement.

       

      Update2

      Setting the environment variable globally (not only for the build agent but in "Manage Jenkins") does the job. But that brings me back to the question: How can you set this variable in a pipeline? I would be very happy about an example

          [JENKINS-74976] Custom fields/tags not added to measurements

          aleksisimell I'd be really happy about a hint here, I'm still stuck with this issue.

          Jan-Frederik Schmidt added a comment - aleksisimell I'd be really happy about a hint here, I'm still stuck with this issue.

          Aleksi Simell added a comment -

          Hi g3n35i5,

          Did you already checkout the plugin documentation? There's a note that explains that if you want to set the variables in a pipeline, you need to create a custom step to export the values with an EnvironmentContributingAction. There's an example how to do this in this PR description , which added the support for adding tags to global listeners.

          To be fair, it took me quite a bit of digging to find that, so I'll add a link to the plugin documentation as well. Thanks for bringing this up!

          Aleksi Simell added a comment - Hi g3n35i5 , Did you already checkout the plugin documentation ? There's a note that explains that if you want to set the variables in a pipeline, you need to create a custom step to export the values with an EnvironmentContributingAction. There's an example how to do this in this PR description , which added the support for adding tags to global listeners. To be fair, it took me quite a bit of digging to find that, so I'll add a link to the plugin documentation as well. Thanks for bringing this up!

          aleksisimell thank you so much for the link to the PR, I didn't search for the information there but in the documentation

          Jan-Frederik Schmidt added a comment - aleksisimell thank you so much for the link to the PR, I didn't search for the information there but in the documentation

          Jan-Frederik Schmidt added a comment - - edited

          aleksisimell I tried your solution and it works. Unfortunately, this introduces a nasty bug/side-effect in my pipelines.

          Since Jenkins is fully file-system based (job status, progress, ...), it serializes job information to disk and de-serializes it upon Jenkins (master) restarts.

          With the publishEnv resp. PublishEnvVarAction action, this de-serialization doesn't work.
          This leads to the following effect: Already successfully finished jobs are tried to be resumed and then are marked as FAILURE.

          [...]
          [Pipeline] End of Pipeline
          [GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published.
          [InfluxDB Plugin] Collecting data...
          [InfluxDB plugin] Custom Data plugin data found. Writing to InfluxDB...
          [InfluxDB plugin] Git plugin data found. Writing to InfluxDB...
          [InfluxDB plugin] Change log plugin data found. Writing to InfluxDB...
          [InfluxDB plugin] Metrics plugin data found. Writing to InfluxDB...
          [InfluxDB Plugin] Publishing data to target 'InfluxDB' (url='XXXXX', database='jenkins')
          [InfluxDB Plugin] Completed.
          
          GitHub has been notified of this commit’s build result
          
          Finished: SUCCESS
          Creating placeholder flownodes because failed loading originals.
          ERROR: Cannot resume build because FlowNode 15 for FlowHead 1 could not be loaded.
          [GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published.
          [InfluxDB Plugin] Collecting data...
          [InfluxDB plugin] Git plugin data found. Writing to InfluxDB...
          [InfluxDB plugin] Change log plugin data found. Writing to InfluxDB...
          [InfluxDB plugin] Metrics plugin data found. Writing to InfluxDB...
          [InfluxDB Plugin] Publishing data to target 'InfluxDB' (url='XXXXX', database='jenkins')
          [InfluxDB Plugin] Completed.
          
          GitHub has been notified of this commit’s build result
          
          Finished: FAILURE
           

          Do you have any idea on how to fix this? I already tried to mark the PublishEnvVarAction as Serializable

          public class PublishEnvVarAction extends InvisibleAction implements EnvironmentContributingAction, Serializable {
              private static final long serialVersionUID = 1L;
          ...
           

          but it didn't work either.

          Jan-Frederik Schmidt added a comment - - edited aleksisimell I tried your solution and it works. Unfortunately, this introduces a nasty bug/side-effect in my pipelines. Since Jenkins is fully file-system based (job status, progress, ...), it serializes job information to disk and de-serializes it upon Jenkins (master) restarts. With the publishEnv resp. PublishEnvVarAction action, this de-serialization doesn't work. This leads to the following effect: Already successfully finished jobs are tried to be resumed and then are marked as FAILURE. [...] [Pipeline] End of Pipeline [GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published. [InfluxDB Plugin] Collecting data... [InfluxDB plugin] Custom Data plugin data found. Writing to InfluxDB... [InfluxDB plugin] Git plugin data found. Writing to InfluxDB... [InfluxDB plugin] Change log plugin data found. Writing to InfluxDB... [InfluxDB plugin] Metrics plugin data found. Writing to InfluxDB... [InfluxDB Plugin] Publishing data to target 'InfluxDB' (url= 'XXXXX' , database= 'jenkins' ) [InfluxDB Plugin] Completed. GitHub has been notified of this commit’s build result Finished: SUCCESS Creating placeholder flownodes because failed loading originals. ERROR: Cannot resume build because FlowNode 15 for FlowHead 1 could not be loaded. [GitHub Checks] GitHub check (name: Jenkins, status: completed) has been published. [InfluxDB Plugin] Collecting data... [InfluxDB plugin] Git plugin data found. Writing to InfluxDB... [InfluxDB plugin] Change log plugin data found. Writing to InfluxDB... [InfluxDB plugin] Metrics plugin data found. Writing to InfluxDB... [InfluxDB Plugin] Publishing data to target 'InfluxDB' (url= 'XXXXX' , database= 'jenkins' ) [InfluxDB Plugin] Completed. GitHub has been notified of this commit’s build result Finished: FAILURE Do you have any idea on how to fix this? I already tried to mark the PublishEnvVarAction as Serializable public class PublishEnvVarAction extends InvisibleAction implements EnvironmentContributingAction, Serializable {     private static final long serialVersionUID = 1L; ... but it didn't work either.

            aleksisimell Aleksi Simell
            g3n35i5 Jan-Frederik Schmidt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: