Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in declaring a json with dynamic values in Jenkinsfile

def props = readJSON text: [ 'buildName':"${params.buildName}",   'targetRepo':"${params.artifactoryReleases}"]
echo props.buildName
echo props.targetRepo

Getting the following error

org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class java.lang.String at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:265) at org.jenkinsci.plugins.structs.describable.DescribableModel.(DescribableModel.java:122) at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:380)

Caused: java.lang.IllegalArgumentException: Could not instantiate {text={buildName=alu-rp, targetRepo=na-generic-releases}} for ReadJSONStep(file?: String, text?: String) at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:264) at org.jenkinsci.plugins.workflow.steps.StepDescriptor.newInstance(StepDescriptor.java:201)

like image 322
Sankarganesh Eswaran Avatar asked Feb 26 '18 07:02

Sankarganesh Eswaran


1 Answers

Since your props are in JSON, you need to convert it to string in order to echo it

Try: echo props.toString()

You can also use print instead, conversion to string is not necessary: print props

like image 53
t-reksio Avatar answered Sep 22 '22 12:09

t-reksio