How do I execute shell script from Jenkins groovy script in the parameters option? -


i want call shell script in uno-choice dynamic reference parameter , perform operation (create files , call other shell scripts called shell script) .

as of able call shell script , cat files not able create new files or call shell script within this.

def sout = new stringbuffer(), serr = new stringbuffer()  // 1)  def proc ='cat /home/path/to/file'.execute() //display contents of file  // 2)  def proc="sh /home/path/to/shell/script.sh".execute() //to call shell script above dosent work if echo contents //into file.  proc.consumeprocessoutput(sout, serr) proc.waitfororkill(1000) return sout.tokenize() 

eg:- in script.sh if add line

echo "hello world" > test 

then test file not created

for more understanding:

groovy executing shell commands

http://jenkins-ci.361315.n4.nabble.com/executing-a-shell-python-command-in-jenkins-dynamic-choice-parameter-plugin-td4711174.html

since running bash scripts groovy wrapper, stdout , stderr redirected groovy wrapper. in order override this, need use exec within shell script.

for example:

the groovy script:

def sout = new stringbuffer(), serr = new stringbuffer()  def proc ='./script.sh'.execute()  proc.consumeprocessoutput(sout, serr) proc.waitfororkill(1000) println sout 

the shell script named script.sh , located in same folder:

#!/bin/bash echo "test redirect" 

running groovy shell script above produce output test redirect on stdout of groovy script

now add stdout redirection exec in script.sh`:

#!/bin/bash exec 1>/tmp/test echo "test redirect" 

now running groovy script create file /tmp/test content test redirect

you can read more i/o redirection in bash here


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -