2013-06-05 49 views
1

之前我目前正在建立一個持續集成系統,詹金斯和我碰到一個問題就來了:詹金斯 - 檢查每一個混帳建立

幾乎每一個項目依賴於其他項目。所以,爲了執行日常構建,我使用了CloudBees Build Flow plugin。實際上,它的工作非常好,但不是最佳方式:它構建了我告訴它的每個工作,如果有任何更改,甚至不檢查Git。所以我想知道在實際構建項目之前是否有任何更改可以強制Jenkins檢查Git。

PS:對不起,我的英語,我不是一個母語

+0

你是說實際的項目源代碼是在git中? – mtk

+0

不,Git以其預期的方式使用:我們使用git commit和git push來更新源代碼。和一個插件一樣,Jenkins可以使用Git作爲SCM – Bosion

回答

0

最終,我選擇了堅守,而不是使用腳本來BuildFlow和Groovy語言,但它只是通過方便,這個解決方案將完全與shell語言一起工作。此外,使用BuildFlow可讓您使用Parallel()同時啓動多個作業。

這裏是我的解決方案:

我發現這個插件Jenkins Poll SCM,該調查試圖建立它(僅在必要時)之前,SCM。

CloudBees Build Flow plugin唯一的問題是它不等待以前的作業完成,因爲我沒有使用build()方法。爲了克服這個問題,我做了自己的buildWithPolling()方法,在繼續之前等待完成這項工作。我的方法唯一的缺點是它不會等待下游作業完成(但我不知道它是否使用build()方法...)。這裏是我的方法的代碼:

def buildWithPolling(project) 
{ 
    //Connection to the URL starting the polling, and starting the building if needed 
    def address = "http://localhost:8080/jenkins/job/" + project + "/poll" 
    println "Connexion à " + address + " pour scrutation du Git et build si besoin est." 
    def poll = new URL(address) 
    poll.openStream() 

    //Declaration of variables used to know if the build is still running, or if it is finished 
    boolean inProgress = true 
    def parser = new XmlParser() 
    def rootNode = null; 
    address = "http://localhost:8080/jenkins/job/" + project + "/lastBuild/api/xml?depth=1&tree=building&xpath=*/building" 

    while(inProgress) { 
     //A 5 seconds pause, because we don't need to overload the server 
     sleep(5000) 
     //Request sent to the server, to know if the job is finished. 
     def baos =new ByteArrayOutputStream() 
     baos << new URL(address).openStream() 
     rootNode = parser.parseText(new String(baos.toByteArray())) 
     inProgress = rootNode.text().toBoolean() 
    } 
} 

這可能不是最好的解決方案,但它是爲我工作的!

0

不知道,如果你已經看過的作業設置的CONFIGS。有一個地方可以強制結賬。我擁有svn鏈接,類似的事情就會用git

enter image description here

如果沒有,你可以找如下圖所示添加的手動命令。請檢查您是否可以安排這個順序先執行然後建立你的任務

enter image description here

+1

不幸的是,Jenkins並不支持Git,你必須安裝一個插件才能使用它。而這個插件沒有這個選項 – Bosion

+0

我認爲這是最好的解決方案。我會解釋我在答案中找到的解決方案 – Bosion