我已经创建了一个复杂的流水线。在每个阶段中,我都调用了一个作业。我想在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
}
}
}
}
}
}
build步骤返回的对象是一个RunWrapper类的对象。调用getRawBuild()方法会返回一个Run对象 - 从这个类的外观来看,可能还有其他选项可以读取日志行。为了使其正常工作,您需要禁用管道沙盒或获取这些方法的脚本批准:
method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
如果您需要对许多构建进行此操作,最好将一些代码放入共享管道库中来执行所需操作,或在管道中定义一个函数。