管道中的控制台输出:Jenkins

vim*_*mal 1 shell jenkins

我创建了一个复杂的管道.在每个阶段,我都打电话给工作.我想在Jenkins的一个阶段看到每个作业的控制台输出.怎么弄?

mac*_*3zr 10

从构建步骤返回的对象可用于查询日志,如下所示:

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
                    }
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

从构建步骤返回的对象是RunWrapper类对象.getRawBuild()调用返回一个Run对象 - 除了从该类的外观逐行读取日志之外,还有其他选项.为此,您需要禁用管道沙箱或获取这些方法的脚本批准:

method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
Run Code Online (Sandbox Code Playgroud)

如果您正在为许多构建执行此操作,那么将一些代码放在管道共享库中以执行您需要的操作或在管道中定义函数是值得的.