从构建步骤返回的对象可用于查询日志,如下所示:
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