【发布时间】:2017-02-28 13:48:06
【问题描述】:
我创建了一个复杂的管道。在每个阶段,我都调用了一份工作。我想在 Jenkins 的一个阶段查看每个作业的控制台输出。如何获得?
【问题讨论】:
我创建了一个复杂的管道。在每个阶段,我都调用了一份工作。我想在 Jenkins 的一个阶段查看每个作业的控制台输出。如何获得?
【问题讨论】:
构建步骤返回的对象可用于查询日志,如下所示:
pipeline {
agent any
stages {
stage('test') {
steps {
echo 'Building anotherJob and getting the log'
script {
def bRun = build 'anotherJob'
echo 'last 100 lines of BuildB'
for(String line : bRun.getRawBuild().getLog(100)){
echo line
}
}
}
}
}
}
从构建步骤返回的对象是RunWrapper 类对象。 getRawBuild() 调用返回一个Run 对象 - 除了从此类的外观逐行读取日志之外,可能还有其他选项。为此,您需要禁用管道沙箱或获得这些方法的脚本批准:
method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
如果您为许多构建执行此操作,则值得将一些代码放入管道共享库中以执行您需要的操作或在管道中定义函数。
【讨论】: