![](/img/trans.png)
[英]Jenkins how to execute particular shell command from the git commit message
[英]How to execute a shell command through groovy
我想在groovy中編寫一個shell命令並通過gradle執行。 例如,我有這個命令:
git log tag2 tag1
這列出了兩個標簽之間完成的提交。 我只想在groovy中寫這個。 目前,我寫的是:
task show <<
{
def fist = "git log new-tag4 new-tag5"
println("[fist]")
Process process = fist.execute()
println(process.text)
}
這個構建成功,但沒有給我結果。 我遺失或做錯了什么?
首先,確保您在正確的目錄中:
Process process = fist.execute(null, new File("your git repo"))
要么:
"git log new-tag4 new-tag5".execute(null, new File("C:\Rep9"))
其次,請確保您看到所有內容(stdout,stderr)以防命令出現問題:
def process=new ProcessBuilder("git log new-tag4 new-tag5").redirectErrorStream(true).directory(new File("your git repo")).start()
process.inputStream.eachLine {println it}
有關詳細信息,請參閱“ 在Groovy中執行shell命令 ”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.