I'm using Jenkins to launch a script on a linux machine.
When I run this manually on the server, it works:
/bin/bash -c '/some/script MyProduct SomeBranch'
When I run this with groovy, it doesn't work.
I get the same error as if I didn't pass the "-c" option, so somehow the "-c" isn't working.
Here is my code:
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 )
Is this the correct way to build the command in Groovy?:
def cmd = "/bin/bash -c '/some/script "+product+" "+branch+"'"
cmd.execute()
Thanks!
Question similar to / helpful resources that I tried:
Try to run the command in the following way:
def cmd = ["/bin/bash", "-c", "/some/script", product, branch]
You may also try:
def cmd = ["/some/script", product, branch]
if /some/script
is executable - BTW is it placed under root (/
)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With