Jenkins Pipeline - 如何从并行构建中获取日志 [英] Jenkins Pipeline - how to get logs from parallel builds
问题描述
是否有可能,如果是:如何?分别获取每个并行步骤的日志输出?
Is it possible, and if yes: how?, to get the log output for each parallel step separately?
即:
def projectBranches = [:]
for (int i = 0; i < projects.size(); i++) {
def _i = i
projectBranches[_i] = {
someFunction(_i)
}
}
parallel projectBranches
现在是否可以获取每个 projectBranches[_i] 的日志?
Is it now possible to get the log for each of projectBranches[_i]?
推荐答案
你可以使用 Jenkins REST API 获取你的节点:job/test/1/api/json?depth=2
You could get your nodes by use of Jenkins REST API: job/test/1/api/json?depth=2
结果应包含以下内容:
{"_class":"org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode","actions":[{},{},{}],"displayName":"Branch: 0","iconColor":"blue","id":"13","parents":["3"],"running":false,"url":"job/test/1/execution/node/13/"},
{"_class":"org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode","actions":[{},{},{}],"displayName":"Allocate node : Start","iconColor":"blue","id":"23","parents":["13"],"running":false,"url":"job/test/1/execution/node/23/"},
{"_class":"org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode","actions":[{},{}],"displayName":"Allocate node : Body : Start","iconColor":"blue","id":"33","parents":["23"],"running":false,"url":"job/test/1/execution/node/33/"},
{"_class":"org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode","actions":[{},{}],"displayName":"Print Message","iconColor":"blue","id":"37","parents":["33"],"running":false,"url":"job/test/1/execution/node/37/"}
因此,对于您的情况,您对具有给定名称的分支的 StepAtomNode 类型的子节点感兴趣(本例中为 0-9).从这里您可以通过简单地将日志添加到地址来获得控制台输出地址(例如:job/test/1/execution/node/37/log).
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).
现在这有点难看,您需要解析 html 以从
Now this is where it gets a bit ugly, you need to parse the html to get the actual log from the
<pre class="console-output">log here
</pre>
这篇关于Jenkins Pipeline - 如何从并行构建中获取日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!