Script groovy in Active Choice Parameter

18 views
Skip to first unread message

Antonio Gomez

unread,
Jun 17, 2020, 8:38:42 AM6/17/20
to Jenkins Users
Hello,

I am trying to display json file content as multiselect within Choice Active Parameter.

This is my code:

//import groovy.json.JsonSlurperClassic
import groovy.json.JsonSlurper

//def parseJsonText(String jsonText) {
//  final slurper = new JsonSlurperClassic()
//  return slurper.parseText(jsonText)
// }



node('master') { 
    

// def fichero = readFile('/var/jenkins_home/workspace/free/dos.json')
// configuracion = parseJsonText(fichero)
//  println configuracion



def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText('{ "server": "axn","server2":"azn" }')
println object 



I have tried JsonSlurper and JsonSlurperClassic libraries.
If the parsing of my json is in text inside the script it works fine, but if I retrieve the json content from a file it doesn't work.
Both codes are tested as pipelines and return the same result.

Any idea?

chencho m-a

unread,
Jun 17, 2020, 8:57:16 AM6/17/20
to Jenkins Users
Is the file correctly formatted? If you have edited from windows, maybe you have wrong line endings

Mahima Mishra

unread,
Jun 17, 2020, 3:36:01 PM6/17/20
to Jenkins Users
Have you tried readJSON from pipeline utility steps plugin?

Antonio Gomez

unread,
Jun 17, 2020, 3:42:51 PM6/17/20
to jenkins...@googlegroups.com
Yes and it works fine, the problem is when when I add a script in the Active Choice Parameters plugin.
I think inside the plugin I can't use readJson, but I'm going to try it.
Thank you

El mié., 17 jun. 2020 a las 21:36, Mahima Mishra (<02.m...@gmail.com>) escribió:
Have you tried readJSON from pipeline utility steps plugin?

--
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/4c5a0711-3b01-49fa-b0eb-2852876bb53eo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages