Using extended choice parameter in Jenkins

2,144 views
Skip to first unread message

VikS

unread,
Mar 9, 2017, 6:31:36 AM3/9/17
to Jenkins Users

I would like to create an Extended Choice Parameter option and for the choices to be listed from a text file? Would it be possible and if yes, how can i achieve that?

Image

Ioannis Moutsatsos

unread,
Mar 9, 2017, 10:04:10 PM3/9/17
to Jenkins Users
Take a look at the Active Choices plugin instead. A simple Groovy script can be used to read the text file and return a list of the choices.

VikS

unread,
Mar 10, 2017, 12:40:41 AM3/10/17
to Jenkins Users
Thank you, I never scripted using Groovy and tried this String fileContents = new File("C:/temp/applicationlist.txt").text which did not work...

Ioannis Moutsatsos

unread,
Mar 10, 2017, 1:55:52 PM3/10/17
to jenkins...@googlegroups.com
Active Choices requires that the returned value from the script is a list or a map. Each element then becomes a selectable option.
Assuming that each line of your text file contains an option you want to display, try something along these lines for the Active Choices groovy script:
def choices=[]
textFile= new File("C:/temp/applicationlist.txt")
textFile.eachLine{
choices.add(it)
}
return choices

--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/tzvYEp76IVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ae1008fe-2229-4c04-93bb-634ad9943011%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

VikS

unread,
Mar 19, 2017, 11:48:02 PM3/19/17
to Jenkins Users
Thank you, the script worked.. :)
Reply all
Reply to author
Forward
0 new messages