【发布时间】:2015-03-25 18:28:13
【问题描述】:
我正在使用 Jenkins 在 linux 机器上启动脚本。
当我在服务器上运行此手动时,它工作:
/bin/bash -c '/some/script MyProduct SomeBranch'
当我使用 groovy 运行此程序时,它不起作用。
我得到的错误与我没有通过“-c”选项一样,所以不知何故“-c”不起作用。
这是我的代码:
branchName = "SomeBranch"
configName = "release"
println "Building for branch "+branchName+" and configuration "+configName
def chkbranch = { String product, String branch -> mkcmd( product, branch ) }
private def mkcmd ( String product, String branch ) {
// Build the command string to run
def cmd = "/bin/bash -c '/some/script "+product+" "+branch+"'"
def sout = new StringBuffer()
def serr = new StringBuffer()
// Run the command
println "running "+cmd
def proc = cmd.execute()
proc.consumeProcessOutput ( sout, serr )
proc.waitForProcessOutput ()
println "out> $sout"
println "err> $serr"
return sout
}
chkbranch ( "MyProduct", branchName )
这是在 Groovy 中构建命令的正确方法吗?:
def cmd = "/bin/bash -c '/some/script "+product+" "+branch+"'"
cmd.execute()
谢谢!
类似于我尝试过的有用资源的问题:
【问题讨论】:
标签: groovy