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

Add STAGE_NAME and NODE_NAME to environment parameters

    Details

    • Similar Issues:

      Description

      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.

        Attachments

          Activity

          Hide
          jbochenski Jakub Bochenski added a comment -

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

          Show
          jbochenski Jakub Bochenski added a comment - I'm not sure what do you mean by "parent build" in the context of Jenkins pipeline
          Hide
          tgatinea 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

           

          Show
          tgatinea 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  

            People

            • Assignee:
              jbochenski Jakub Bochenski
              Reporter:
              tgatinea Thierry GATINEAU
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: