2016-11-25 86 views
1

背景

比方說,我有兩個工作,一個是「管道作業」和一個「構建作業」。 '管道工作'運行在master上,當然是一個管道(使用groovy)。然後,對於管道中的構建部分,我使用在Windows上運行的一個從站,即「構建作業」,它負責構建我在主站無法完成的任務。主人也在Windows上運行,但缺少特定版本所需的一些軟件。Jenkins管道:獲取從站代理的構建輸出

問題

我有一個Groovy腳本,看起來是這樣的:

#!groovy 
node { 
    stage('Environment Preparation') { 
     // fetches stuff and sets up the environment on master 
    } 
    stage('Unit Testing') { 
     // some testing 
    } 
    stage('Build on Slave') { 
     def slaveJob = build job: 'BuildJob' 
    } 
} 

它工作正常,其中「BuildJob」是「限制,其中該項目可以運行」,即在奴隸。

我的問題是,我想'BuildJob'的輸出在管道日誌中打印。你有一些聰明的方法可以做到這一點?我爲所有事情開放,所以如果你知道更多聰明的方式來啓動'BuildJob'等,我很想在這裏。

謝謝!

回答

2

EDITED 您必須批准您在腳本審批時要訪問的內容。不知道你是否真的需要getRawBuild,但它的工作。

Search through console output of a Jenkins job

#!groovy 
node { 
    stage('Environment Preparation') { 
     // fetches stuff and sets up the environment on master 
    } 
    stage('Unit Testing') { 
     // some testing 
    } 
    stage('Build on Slave') { 
     def slaveJob = build job: 'BuildJob' 
     println slaveJob.rawBuild.log 
    } 
} 

jenkinsurl/scriptApproval /您同意以下內容:

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

不幸我得到「* org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException:未分類的字段org.jenkinsci.plugins.workflow.support.steps.build。RunWrapper log *「試用您的解決方案 –

+0

白名單方法: https://github.com/jenkinsci/workflow-support-plugin/blob/master/src/main/java/org/jenkinsci/plugins/workflow/support/steps /build/RunWrapper.java – MaTePe

+0

是啊,這可能有用,但我沒有時間恢復和測試它。謝謝你的時間! –

1

那麼,有時會提出一個問題讓你從另一個角度思考。

希望有人會從中受益。 我偶然發現了一個Pipeline-Plugin tutorial,他們在那裏展示瞭如何使用節點來標記腳本代碼應該在哪裏運行。產生的常規文件看起來是這樣的:

#!groovy 
stage('Environment Preparation') { 
    node('master') { 
     // fetches stuff and sets up the environment on master 
    } 
} 
stage('Unit Testing') { 
    node('master') { 
     // some testing 
    } 
} 
stage('Build on Slave') { 
    node('remote') { 
     def out = bat script: 'C:\\Build\\build.bat', returnStdout: true 
    } 
} 

正如你所看到的教程讓我重構腳本一點。 節點('remote')部分是定義即將到來的東西應該在從屬機器上運行的部分。

我不得不在批處理腳本中進行一些自定義,以便將所有重要的內容打印到標準輸出。

你必須讓詹金斯知道哪個節點是去到「遠程」管理詹金斯>管理節點,選擇記從代理,配置節點並添加「遠程」或者是適合你的標籤字段。

+0

你能不能做這樣的事? http://stackoverflow.com/questions/36188512/search-through-console-output-of-a-jenkins-job 所以你第一次編碼,然後只是「println slaveJob.log」? – MaTePe