简体   繁体   English

詹金斯与groovy脚本

[英]Jenkins with groovy script

I'm using groovy to get some parameters to run jobs in jenkins. 我正在使用groovy获取一些参数以在jenkins中运行作业。

My question is why script A work's and B and C don't 我的问题是为什么脚本A的作品和B和C的作品不一样

A 一种

def sout = new StringBuilder(), serr = new StringBuilder()
def proc = 'ls -D --format=single-column /path/folder'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
return sout.tokenize()

B The \\\\ is to escape \\ B \\\\是逃脱\\

def proc = 'find /path/folder/ -type f \\( -iname \\*.ear -o -iname \\*.war \\)'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
return sout.tokenize()

C script.sh return a list of files C script.sh返回文件列表

def sout = new StringBuilder(), serr = new StringBuilder()
def proc = '/scripts/script.sh'.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
println "out> $sout err> $serr"
return sout.tokenize()

There is some jenkins restriction to run scripts from groovy or certainly shell commands? 有一些jenkins限制来运行groovy或shell命令中的脚本吗?

After a lot of tries I can make this work. 经过很多尝试,我可以使这项工作。

if (Origem.equals('FILE')) {
def cmd = ["/bin/bash","-c","/opt/scripts/SearchPackage.sh"]
def sout = new StringBuffer()
def serr = new StringBuffer()
def proc = cmd.execute()
proc.consumeProcessOutput ( sout, serr )
proc.waitForProcessOutput ()
return sout.tokenize()
}

Groovy was not recognizing the // character as an escape for '/'. Groovy没有将//字符识别为'/'的转义符。 I just decide put everything in a shell script and use groovy to call this script. 我只是决定将所有内容都放入一个shell脚本中,并使用Groovy来调用此脚本。 THe problem was solved but if someone has a better aproach I will be glad. 这个问题已经解决了,但是如果有人有更好的方法,我会很高兴的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM