groovy – 使用选项和参数执行shell脚本
我正在使用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 execute with parameters containing spaces 解决方法
尝试以下列方式运行该命令:
def cmd = ["/bin/bash","-c","/some/script",product,branch] 您也可以尝试: def cmd = ["/some/script",branch] if / some / script是可执行的 – BTW是否置于root(/)下? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |