管道中的控制台输出:Jenkins [英] Console Output in pipeline:Jenkins
问题描述
我创建了一个复杂的管道.在每个阶段,我都要求一份工作.我想在Jenkins的某个阶段中查看每个作业的控制台输出.如何获得?
I have created a complex pipeline. In each stage I have called a job. I want to see the console output for each job in a stage in Jenkins. How to get it?
推荐答案
从构建步骤返回的对象可用于查询日志,如下所示:
The object returned from a build step can be used to query the log like this:
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
}
}
}
}
}
}
从构建步骤返回的对象是运行对象-除了从此类的外观逐行读取日志外,还有其他选择.为此,您需要禁用管道沙箱或获取这些方法的脚本批准:
The object returned from the build step is a RunWrapper class object. The getRawBuild() call is returning a Run object - there may be other options than reading the log line-by-line from the looks of this class. For this to work you need to either disable the pipeline sandbox or get script approvals for these methods:
method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
如果要对许多构建都执行此操作,则有必要将一些代码放入管道共享库中以执行所需的操作或在管道中定义函数.
If you are doing this for many builds, it would be worth putting some code in a pipeline shared library to do what you need or define a function in the pipeline.
这篇关于管道中的控制台输出:Jenkins的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!