Is it possible, and if yes: how?, to get the log output for each parallel step separately?
I.e.:
def projectBranches = [:]
for (int i = 0; i < projects.size(); i++) {
def _i = i
projectBranches[_i] = {
someFunction(_i)
}
}
parallel projectBranches
Is it now possible to get the log for each of projectBranches[_i]?
You could get your nodes by use of Jenkins REST API: job/test/1/api/json?depth=2
Result should contain something like:
So for your case you are interested in the child with type StepAtomNode of your Branch with name given (0-9 for this case). From this you could obtain console output address by simply adding log to the address (like: job/test/1/execution/node/37/log).
Now this is where it gets a bit ugly, you need to parse the html to get the actual log from the
I needed to access logs from within the pipeline code
so I implemented the algorithm proposed by キキジキ (really helpful) with a few adjustments (to add branchName prefix on each line to be able to get the whole log and still figure out which branch corresponds to each line ; and to support nested branches, which I needed) in https://github.com/gdemengin/pipeline-logparser :
to get logs programmatically
to get the full logs with branch prefix (similar to what
currentBuild.rawBuild.log
returned before version 2.2.5 of workflow-job plugin. but in version 2.26 they got rid of the branch information and I could not find any built-in function with the same information)String logs = logparser.getLogsWithBranchInfo()
get the logs from 'branch2' only
String logsBranch2 = logparser.getLogsWithBranchInfo(filter: ['branch2'])
to archive logs (in as $JOB_URL/<runId>/artifacts) to have them available as a link for later use
to archive the full logs (with branch prefix)
logparser.archiveLogsWithBranchInfo('consoleText.txt')
to archive the logs from branch2 only
logparser.archiveLogsWithBranchInfo('logsBranch2.txt', [filter: ['branch2']])
I found a way to achieve that, but you need to access the build folder directly (for example using
currentBuild.rawBuild.getLogFile().getParent()
).flowNodeStore.xml
file) inside theworkflow
directory:<id>
and<parentIds>
values.<branchName>
is defined associate it to the current node and recursively to all nodes that have this node as parent. If a node has multiple parents assign no branch value to it.log
file asbyte[]
.log-index
to find log ranges to assign to each node. The format of a line can be one of the following:offset nodeId
-> start of new node range, end of the previous (if present).offset
: end of current node range.new String(range, "UTF-8")
).replaceAll("\u001B.*?\u001B\\[0m", "")