I am trying to run a job from a rest API, but it fails with the below error. It works well from my local system but creates an issue when trying to run it from other sever -
Command I’m using:
curl -v --location --request POST ‘https://localhost.com/job/Restart/buildWithParameters?token=****’ --user username:token --form ‘ENVIRONMENT= “DEV”’ --form ‘SERVICE= “RESTART”’ --form ‘SERVER= “BOTH”’
We need more than “there was an error” Have you checked the system logs under configuration (or $JENKINS_HOME/logs on disk)? does it give yo any information?
Here is what I see in logs. But the parameters are defined well on Jenkins jobs. Also it works well from my local system, but not from my test server.
Command:
curl -v --location --request POST ‘https://localhost.com/job/Restart/buildWithParameters?token=****’ --user username:token --form ‘ENVIRONMENT= “DEV”’ --form ‘SERVICE= “RESTART”’ --form ‘SERVER= “BOTH”’
Logs:
java.lang.IllegalArgumentException: Illegal choice for parameter ENVIRONMENT: “DEV”
at hudson.model.ChoiceParameterDefinition.checkValue(ChoiceParameterDefinition.java:163)
at hudson.model.ChoiceParameterDefinition.createValue(ChoiceParameterDefinition.java:170)
at hudson.model.ChoiceParameterDefinition.createValue(ChoiceParameterDefinition.java:29)
at hudson.model.SimpleParameterDefinition.createValue(SimpleParameterDefinition.java:39)
at hudson.model.ParametersDefinitionProperty.buildWithParameters(ParametersDefinitionProperty.java:183)
at jenkins.model.ParameterizedJobMixIn.doBuildWithParameters(ParameterizedJobMixIn.java:237)
at jenkins.model.ParameterizedJobMixIn$ParameterizedJob.doBuildWithParameters(ParameterizedJobMixIn.java:417)
at java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:393)
at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:405)
at org.kohsuke.stapler.Function.bindAndInvoke(Function.java:208)
at org.kohsuke.stapler.Function.bindAndInvokeAndServeResponse(Function.java:141)
at org.kohsuke.stapler.MetaClass$11.doDispatch(MetaClass.java:536)
at org.kohsuke.stapler.NameBasedDispatcher.dispatch(NameBasedDispatcher.java:58)
at org.kohsuke.stapler.Stapler.tryInvoke(Stapler.java:766)
Caused: javax.servlet.ServletException
are you using smart quotes or is that an artifact of discourse? I think jenkins is seeing literally space, smart quote, capital d, capital e, capital v, smart quote but I think you want just capital d, capital e, capital v
try --form=ENVIRONMENT=DEV or if you want to quote it, "--form=ENVIRONMENT=DEV"