Shell 管道中的控制台输出:Jenkins

Shell 管道中的控制台输出:Jenkins,shell,jenkins,Shell,Jenkins,我创建了一个复杂的管道。在每一个阶段,我都要找一份工作。我想在Jenkins中看到阶段中每个作业的控制台输出。如何获取它?从构建步骤返回的对象可用于如下方式查询日志: pipeline { agent any stages { stage('test') { steps { echo 'Building anotherJob and getting the log' sc

我创建了一个复杂的管道。在每一个阶段,我都要找一份工作。我想在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
                    }
                }
            }
        }
    }
}
生成步骤返回的对象是类对象。getRawBuild()调用正在返回一个对象-除了从此类的外观逐行读取日志之外,可能还有其他选项。为此,您需要禁用管道沙箱或获得以下方法的脚本批准:

method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild

如果您对许多构建执行此操作,则值得在管道共享库中放入一些代码,以执行您需要的操作或在管道中定义函数。

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

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
                    }
                }
            }
        }
    }
}
生成步骤返回的对象是类对象。getRawBuild()调用正在返回一个对象-除了从此类的外观逐行读取日志之外,可能还有其他选项。为此,您需要禁用管道沙箱或获得以下方法的脚本批准:

method hudson.model.Run getLog int
method org.jenkinsci.plugins.workflow.support.steps.build.RunWrapper getRawBuild
如果您正在为许多构建执行此操作,那么在管道共享库中放入一些代码以执行您需要的操作或在管道中定义函数是值得的