[英]Jenkins - check Git before every builds
我目前正在與Jenkins建立持續整合系統,但遇到一個問題:
幾乎每個項目都依賴於其他項目。 因此,為了執行日常構建,我使用CloudBees Build Flow插件 。 實際上,它很好地完成了工作,但不是以一種最佳的方式進行工作:它構建了我告訴它的每個工作,甚至沒有檢查Git是否有任何更改。 因此,我想知道是否有任何方法可以迫使詹金斯在實際構建項目之前檢查Git是否存在任何更改。
PS:很抱歉我的英語,我不是母語
不確定,如果您查看了作業設置中的配置。 有一個地方可以進行新的結帳。 我已經svn鏈接,類似的事情將與git
如果沒有,您可以尋找添加手動命令,如下所示。 檢查是否可以安排執行此命令的順序,然后再構建任務
最后,我選擇了堅持使用BuildFlow和Groovy語言,而不是使用腳本,但這只是為了方便,此解決方案將完全適用於Shell語言。 此外,使用BuildFlow允許您使用Parallel()來同時啟動多個作業。
這是我的解決方案:
我找到了Jenkins Poll SCM插件,該插件會在嘗試構建SCM之前先對其進行輪詢(僅在必要時)。
CloudBees Build Flow插件的唯一問題是它不等待以前的作業完成,因為我沒有使用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()
}
}
可能這不是最好的解決方案,但是它對我有用!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.