I am trying to use the Jenkins pipeline for Json format input. I am trying to pass the Json format String in multiline string parameter where I am passing parameter like below image but I am not able to able to parse it using JsonSlurper, where test is the name of the multiline string input. Can anyone help me how can I parse it in groovy?
Is it possible to parse the Json format in multiline string parameter ?
multiline string parameter input as Json
def jsonSlurper = new JsonSlurper();
def infra = jsonSlurper.parse($test) ;
CodePudding user response:
You don't have to use JsonSulper for this, you can use readJson step instead. Here is a complete sample.
pipeline {
agent any
parameters { string(name: 'JSON', defaultValue: 'staging', description: '') }
stages {
stage ("Example") {
steps {
script{
def jsonObj = readJSON text: "${params.JSON}"
echo "$jsonObj"
} }
}
}
}