Script groovy in Active Choice Parameter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Script groovy in Active Choice Parameter

Antonio Gomez
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/74f81861-4303-4e4a-a58a-4c7a9e6c4fbfo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Script groovy in Active Choice Parameter

chencho m-a
Is the file correctly formatted? If you have edited from windows, maybe you have wrong line endings

El miércoles, 17 de junio de 2020, 14:38:42 (UTC+2), Antonio Gomez escribió:
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?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/8e65a59a-5be6-4e76-a5d4-b469f38fe77co%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Script groovy in Active Choice Parameter

Mahima Mishra
In reply to this post by Antonio Gomez
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4c5a0711-3b01-49fa-b0eb-2852876bb53eo%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: Script groovy in Active Choice Parameter

Antonio Gomez
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 (<[hidden email]>) 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/4c5a0711-3b01-49fa-b0eb-2852876bb53eo%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CACr-XEnkp6L%2B8pt_2URv0HGG5JRwSofrMX2WWBcgE4YFs%2BCKPw%40mail.gmail.com.