[英]Executing Groovy command through Jenkins: "find: missing argument to `-exec'"
[英]Groovy executing mvn command
我正在編寫 groovy 腳本並嘗試使用 execute() 方法執行以下 shell 命令
"mvn clean install -f \{pom directory}\pom.xml".execute()
但收到以下消息錯誤
“無法運行程序“mvn”:錯誤=2,沒有這樣的文件或目錄”
當然,maven 已經安裝,並且該命令在終端上運行良好....
我也嘗試使用“sc -c”前綴。
"sh -c mvn clean install -f \<pom directory\pom.xml".execute()
但這並沒有執行任何操作,也沒有任何錯誤。 似乎該命令被忽略了。
那么我應該如何在 groovy 腳本中執行 maven install 呢?
我正在編寫 groovy 腳本並嘗試使用 execute() 方法執行以下 shell 命令
"mvn clean install -f \{pom directory}\pom.xml".execute()
但收到以下消息的錯誤
“無法運行程序“mvn”:錯誤=2,沒有那個文件或目錄”
當然,maven 已經安裝好了,並且命令在終端上運行良好....
我也嘗試過使用“sc -c”前綴。
"sh -c mvn clean install -f \<pom directory\pom.xml".execute()
但這確實不執行任何操作,也根本沒有錯誤。 似乎該命令被忽略了。
那么我應該如何在 groovy 腳本中執行 maven install 呢?
在 windows 上,mvn 不是 exe 文件,而是命令 (mvn.cmd)。 我通過以下方式解決了這個問題:
def cmd = ""
if (System.properties['os.name'].toLowerCase().contains('windows')) {
println "On Windows mvn is a CMD and not an EXE"
cmd = "mvn.cmd wrapper:wrapper"
} else {
println "Execute just the mvn executable on non Windows systems"
cmd = "mvn wrapper:wrapper"
}
def process = cmd.execute(null, rootDir)
process.waitForProcessOutput((Appendable)System.out, System.err)
if (process.exitValue() != 0) {
println "WARNING: Command '$cmd' exited with code: ${process.exitValue()}"
println "WARNING: you can initialize the maven wrapper by yourself:}"
println "WARNING: go to $rootDir and type in 'mvn wrapper:wrapper'}"
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.