'Jenkins - Prefix all logs with node name?
What I am looking for is basically the same functionality that Timestamper provides, but in addition to showing the time for each line, I also want to see which node it was running on.
Instead of this:
13:35:12 > Task :compileJava NO-SOURCE
13:35:12 > Task :processResources NO-SOURCE
13:35:12 > Task :classes UP-TO-DATE
13:35:12 > Task :compileTestJava NO-SOURCE
13:35:12 > Task :processTestResources NO-SOURCE
13:35:12 > Task :testClasses UP-TO-DATE
13:36:39 fatalError
I want this (or similar):
13:35:12 [mac-01] > Task :compileJava NO-SOURCE
13:35:12 [mac-01] > Task :processResources NO-SOURCE
13:35:12 [mac-01] > Task :classes UP-TO-DATE
13:35:12 [mac-01] > Task :compileTestJava NO-SOURCE
13:35:12 [mac-01] > Task :processTestResources NO-SOURCE
13:35:12 [mac-01] > Task :testClasses UP-TO-DATE
13:36:39 [mac-01] fatalError
We have pipelines that run multiple builds on multipe nodes in parallel and sometimes they fail due to problems with a specific node. If each line in the log was prefixed with the node it was running on, it would be quite trivial to find out which node is having an issue. As it stands now, it can be rather challenging.
I've been trying to search for something like this on Google, but the terms are a bit too generic and I'm not getting any relevant results.
Solution 1:[1]
What you are looking for is label attribute.
This label attribute is available for all bat, sh, powershell and others. https://www.jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script
bat( script: ```Some Script ```,
label: "${env.NODE_NAME}"
)
Your execution will then be pre fixed with the NODE_NAME where the task is running.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Siddharth Kaul |
