您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

管道中的控制台输出:Jenkins

管道中的控制台输出: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
                    }
                }
            }
        }
    }
}

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

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

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

其他 2022/1/1 18:14:25 有457人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶