簡體   English   中英

管道中的控制台輸出:Jenkins

[英]Console Output in pipeline: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

如果要對許多構建都執行此操作,則有必要將一些代碼放入管道共享庫中以執行所需的操作或在管道中定義函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM