同理,我們可以獲取Git的提交歷史:
//enter to the exist folder, and get the commit list
def proca = [ 'bash', '-c', 'cd /root/temp/test.git; git log --all -20 --pretty=\"%h\"' ]
//trans the str to list by line sep.
proca.execute().text.tokenize('\n')
1
2
3
4
5
|
//enter to the exist folder, and get the commit list
def proca = [ 'bash', '-c', 'cd /root/temp/test.git; git log --all -20 --pretty=\"%h\"' ]
//trans the str to list by line sep.
proca.execute().text.tokenize('\n')
|
當我們點擊“build with parameter”的時候,我們看到的效果是,實時的動態列表已經生成了:
Groovy的應用場景還有很多很多,這里就不做具體的介紹了,大家有空可以研究研究,當然,前提是你需要稍微有一點Groovy或者Java的基礎才行。Groovy腳本絕對能讓你的CI工作事半功倍。
原文轉自:hhttp://scmbob.org/groovy-in-jenkins.html