我正在使用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()
谢谢!
我尝试过类似/有用资源的问题:
答案 0 :(得分:5)
尝试以下列方式运行命令:
def cmd = ["/bin/bash", "-c", "/some/script", product, branch]
您也可以尝试:
def cmd = ["/some/script", product, branch]
如果/some/script
是可执行的 - BTW是否置于根目录下(/
)?