简体   繁体   中英

Jenkins with groovy script

I'm using groovy to get some parameters to run jobs in jenkins.

My question is why script A work's and B and C don't

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 \\

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

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?

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 '/'. I just decide put everything in a shell script and use groovy to call this script. THe problem was solved but if someone has a better aproach I will be glad.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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