0

I am trying to use active choice parameters in jenkins . I am executing a shell command and trying to show the output in the choice parameters. 1) Working scenario -

Text file already generated by the output of shell command and able to see the parameters -

list = []
def process = "cat /home/ansible/test1.txt".execute()
process.text.eachLine {list.add it}
return list

Here test1.txt is already populated with the values

2) Failure scenario Instead of pre-populating the file trying the get the shell command output and write into a file and then show it to the choice parameters-

list = []
def process1=" sh script.sh > test1.txt".execute()
def process = "cat /home/ansible/test1.txt".execute()
process.text.eachLine {list.add it}
return list

This is not working

Is there any suggestions ?

2

1 Answer 1

1

Use pure groovy to read file lines

new File('/home/ansible/test1.txt').readLines()

For your case - wrap your code with try-catch to see the error.

Without error message it's hard to help you...

try{
  def list ....
}catch(e){ return [e.toString()] }
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks . But in Jenkins , where should I get the groovy script related errors.
you should see the output in the Jenkins server log.
With try-catch you should see error directly in drop-down. BTW, the other problem in your code - you are not waiting till the end of the process.
Thanks , I solved it . It seems I was using some environment variable which wasn't getting evaluated , could you pls elaborate "not waiting till the end of the process" ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.