2017-02-28 155 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