2017-02-28 149 views
1

我创建了一个复杂的管道。在每个阶段我都要求一份工作。我想在Jenkins的舞台上看到每个工作的控制台输出。如何得到它?控制台管道输出:Jenkins

回答

4

从构建步骤返回的对象可以用来查询日志这样的:

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 

如果您是许多建立这样做,这将是值得投入管道共享库中的一些代码,这样做你需要什么或在管道中定义一个功能。

+0

非常感谢! – vimal