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

Add STAGE_NAME and NODE_NAME to environment parameters

      I use logstash-plugin to send console logs to a server Graylog.

      The jenkins job is a declarative pipeline with several stages that runs in parallel on different kind of agent (See attached example).

      I expected to find in Graylog, for each line of the console logs, the environment variables of the stage that is running with at least the environment variables such as STAGE_NAME and NODE_NAME that would help to extract logs for a dedicated stage.

      But I found in Graylog environment variables of the parent build and therefore I don't find the STAGE_NAME and the NODE_NAME.

      As the stage might run in parallel, the logs of each stages are mixed and it is impossible to setup some graylog filters to watch a dedicated stage.

      I would like to have the NODE_NAme to discover some correlation between errors that might be seen in the log and the agent that was running the stage.

      I dig inside the code and found in BuildData.java that it was the build.getEnvironment(listener) that recovers the environment variables of the parent build.

      If I want to make some evolution of the plugin, what advise would you give to recover the environment parameters of the stage instead of the parent build in BuildData.java? 
      I did not found any solution via the variable "build".

      Thanks by advance for any help.

          [JENKINS-61735] Add STAGE_NAME and NODE_NAME to environment parameters

          I'm not sure what do you mean by "parent build" in the context of Jenkins pipeline

          Jakub Bochenski added a comment - I'm not sure what do you mean by "parent build" in the context of Jenkins pipeline

          I mean that the recovering of build.getEnvironment() provides only a subset of environment variables that does not includes the STAGE_NAME and the NODE_NAME parameters.

          I've figured out how to recover the whole set of environment variables thanks to: 

          hudson.EnvVars envVars = context.get(hudson.EnvVars.class);

          I've prepared and tested some code that can be found in https://github.com/jenkinsci/logstash-plugin/pull/92

           

          Thierry GATINEAU added a comment - I mean that the recovering of build.getEnvironment() provides only a subset of environment variables that does not includes the STAGE_NAME and the NODE_NAME parameters. I've figured out how to recover the whole set of environment variables thanks to:  hudson.EnvVars envVars = context.get(hudson.EnvVars.class); I've prepared and tested some code that can be found in https://github.com/jenkinsci/logstash-plugin/pull/92  

            jbochenski Jakub Bochenski
            tgatinea Thierry GATINEAU
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: