Cannot call openshift.create with String
Closed this issue · 3 comments
The doc says you can :).
Cannot cast object '...' with class 'java.lang.String' to class 'java.util.HashMap'
openshift.withCluster('Webster Sandbox') {
openshift.withProject( 'dev-myuser' ) {
openshift.create("""
{
"apiVersion": "v1",
"kind": "Route",
"metadata": {
"name": "helloworld-rte-act2"
},
"spec": {
"host": "helloworld-dev-act.domain.com",
"to": {
"kind": "Service",
"name": "helloworld-svc-act"
}
},
"tls": {
"termination": "edge"
},
"status": {}
}
""");
println openshift.selector('route', 'helloworld-rte-act2').object()
}
}
hudson.remoting.ProxyException: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '
{
"apiVersion": "v1",
"kind": "Route",
"metadata": {
"name": "helloworld-rte-act2"
},
"spec": {
"host": "helloworld-dev-act.domain.com",
"to": {
"kind": "Service",
"name": "helloworld-svc-act"
}
},
"tls": {
"termination": "edge"
},
"status": {}
}
' with class 'java.lang.String' to class 'java.util.HashMap'
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:405)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:319)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:232)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:603)
at com.openshift.jenkins.plugins.OpenShiftDSL.toSingleObject(OpenShiftDSL.groovy:440)
at com.openshift.jenkins.plugins.OpenShiftDSL$toSingleObject$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:18)
at com.openshift.jenkins.plugins.OpenShiftDSL.objectDefAction(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:465)
at com.openshift.jenkins.plugins.OpenShiftDSL.create(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:496)
at WorkflowScript.run(WorkflowScript:3)
at com.openshift.jenkins.plugins.OpenShiftDSL.withProject(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:283)
at com.openshift.jenkins.plugins.OpenShiftDSL$Context.run(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:76)
at com.openshift.jenkins.plugins.OpenShiftDSL.withProject(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:282)
at WorkflowScript.run(WorkflowScript:2)
at com.openshift.jenkins.plugins.OpenShiftDSL.withCluster(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:272)
at com.openshift.jenkins.plugins.OpenShiftDSL$Context.run(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:76)
at com.openshift.jenkins.plugins.OpenShiftDSL.withCluster(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:271)
at com.openshift.jenkins.plugins.OpenShiftDSL.node(jar:file:/C:/Users/mrichar2/.jenkins/plugins/openshift-jenkins-pipeline-dsl/WEB-INF/lib/openshift-jenkins-pipeline-dsl.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:1088)
at cps.transform(Native Method)
at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
at sun.reflect.GeneratedMethodAccessor192.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock$LocalVariable.get(LocalVariableBlock.java:39)
at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
at com.cloudbees.groovy.cps.impl.LocalVariableBlock.evalLValue(LocalVariableBlock.java:28)
at com.cloudbees.groovy.cps.LValueBlock$BlockImpl.eval(LValueBlock.java:55)
at com.cloudbees.groovy.cps.LValueBlock.eval(LValueBlock.java:16)
at com.cloudbees.groovy.cps.Next.step(Next.java:58)
at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:33)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:30)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:30)
at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:163)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:324)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:78)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:236)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:224)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:63)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE
public HashMap toSingleObject(Object obj ) {
should be
public Object toSingleObject(Object obj ) {
Fixed by #4 .
I now owe you a fine, imported beer :-)
Out of curiosity, why did you prefer a string over modeling your object in Groovy (e.g. https://github.com/jupierce/openshift-jenkins-pipeline-dsl#creating-objects-easier-than-you-were-expecting-hopefully)?
So I could be lazy and copy paste my json file directly without playing with []. {}, and quotes.