I want to change the version value in the package.json file, but I am getting the following error. I can read the version but I get the following error while changing version value. How can i solve it.
org.kohsuke.stapler.NoStaplerConstructorException: There's no @DataBoundConstructor on any constructor of class java.lang.String
at org.kohsuke.stapler.ClassDescriptor.loadConstructorParamNames(ClassDescriptor.java:288)
at org.jenkinsci.plugins.structs.describable.DescribableModel.<init>(DescribableModel.java:153)
at org.jenkinsci.plugins.structs.describable.DescribableModel.coerce(DescribableModel.java:474)
at org.jenkinsci.plugins.structs.describable.DescribableModel.injectSetters(DescribableModel.java:429)
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:331)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:305)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
Caused: java.lang.IllegalArgumentException: Could not instantiate {file={name=demo, version=0.0.0-alpha.0, dependencies={@testing-library/jest-dom=^5.16.5, @testing-library/react=^13.4.0, @testing-library/user-event=^13.5.0, react=^18.2.0, react-dom=^18.2.0, react-scripts=5.0.1, web-vitals=^2.1.4}, scripts={start=react-scripts start, build=react-scripts build, test=react-scripts test, eject=react-scripts eject, sonar-scanner=node_modules/sonar-scanner/bin/sonar-scanner}, eslintConfig={extends=[react-app, react-app/jest]}, browserslist={production=[>0.2%, not dead, not op_mini all], development=[last 1 chrome version, last 1 firefox version, last 1 safari version]}, description=## Available Scripts, main=index.js, repository={type=git, url=git ssh://[email protected]/***.git}, keywords=[**, Demo, UI], publishConfig={registry=http://****/repository/npm-private/}}} for org.jenkinsci.plugins.pipeline.utility.steps.json.WriteJSONStep
at org.jenkinsci.plugins.structs.describable.DescribableModel.instantiate(DescribableModel.java:334)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:305)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:196)
at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:124)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:47)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
code in groovy file:
def updateProjectPackage(params) {
packageFile = readJSON(file: 'package.json')
//params.appVersion = 0.0.0-alpha.0
packageFile.version = params.appVersion
writeJSON file: packageFile
}
package.json
{
"name": "demo",
"version": "0.1.0"
}
CodePudding user response:
Your writeJSON
part seems wrong. It should be something like this.
writeJSON file: 'package.json', json: packageFile