Thanks for the details, I managed to test the CustomDescribableModel within
the pipeline-model-definition plugin and it seems the customInstantiate
happens after the transformToRuntimeAST
<https://github.com/jenkinsci/pipeline-model-definition-plugin/blob/master/pipeline-model-extensions/src/main/java/org/jenkinsci/plugins/pipeline/modeldefinition/when/DeclarativeStageConditionalDescriptor.java#L64>,
in other words, I'm able to manipulate the content of the parameters but I
cannot manipulate and infer the deprecated parameter as the new parameter
since there is a MultipleCompilationErrorsException :_(
*As an example:*
"value" is deprecated and 'pattern' is the new parameter for the
hypothetical case of changing the `environment when` condition in the
declarative pipeline definition.
Then the below implementation of the customInstantiate doesn't work when
using environment name: 'FOO', pattern: 'BAR'
private final String name;
@Deprecated
private transient String value;
private String pattern;
@DataBoundConstructor
public EnvironmentConditional(String name, String pattern) {
this.name= name;
this.pattern = pattern;
}
...
protected Object readResolve() throws IOException {
if (this.value != null) {
this.pattern = this.value;
}
return this;
}
@Extension
@Symbol("environment")
public static class DescriptorImpl extends
DeclarativeStageConditionalDescriptor<EnvironmentConditional> {
...
@Override
public Expression transformToRuntimeAST(@CheckForNull ModelASTWhenContent
original) {
return ASTParserUtils.transformWhenContentToRuntimeAST(original);
}
@Override
public Map<String, Object> customInstantiate(Map<String, Object>
arguments) {
Map<String, Object> r = new HashMap<>(arguments);
Object value = r.get("value");
if (value instanceof String) {
r.put("pattern", ((String) value));
}
return r;
}
}
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup
failed:
WorkflowScript: 90: Invalid parameter "value", did you mean "name"? @ line
90, column 42.
environment name: "FOO", value: "BA
^
1 error
at
org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at
org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
at
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
at
org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
at
org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:126)
at
org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:561)
at
org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:522)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:320)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
Most likelly It's something else that I'm missing though. Although the few
examples I've just found for the customInstantiate where about to
manipulate the content or remove some of the parameters.
Any clues what I'm missing?
Thanks again
--
You received this message because you are subscribed to the Google Groups
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jenkinsci-dev/727fa10e-189f-4430-a9da-57c4009bb651%40googlegroups.com.