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

3,898 views
Skip to first unread message

Shubham Sharma

unread,
May 15, 2015, 9:34:49 AM5/15/15
to jenkins...@googlegroups.com


I want to call a shell script in the Uno-Choice Dynamic Reference Parameter and perform some operation (create some files and call some other shell scripts from the called shell script) .

As of now I am able to call shell script and cat some files but I am not able to create new files or call another shell script from 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 a shell script but the above dosent work if I echo some contents
//into some file.

proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
return sout.tokenize()
eg:- in script.sh if I add line
echo "hello world" > test

then test file is not created but instead if I do 

echo "hello world" 

It gets printed on the Jenkins console

for more understanding:

http://stackoverflow.com/questions/30253684/how-do-i-execute-shell-script-from-jenkins-groovy-script-in-the-parameters-optio?noredirect=1#comment48608118_30253684

Please help.


Regards

Shubham

Baptiste Mathus

unread,
May 15, 2015, 11:25:09 AM5/15/15
to jenkins...@googlegroups.com
Please stop crossposting. This is a user list question.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f8a6ba4c-c3ba-40c6-959b-acd480bc1ad0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor !
Reply all
Reply to author
Forward
0 new messages