Nullable single constructor parameter with declarative pipeline

42 views
Skip to first unread message

Julien HENRY

unread,
Mar 19, 2018, 6:48:38 AM3/19/18
to jenkin...@googlegroups.com
Hi folks,

Our SonarQube plugin has a build step that contains a "single nullable parameter":

@DataBoundConstructor
public OurStep(@Nullable String param) {
  //
}

This allows users to use one of the two syntaxes in their scripted pipelines:

ourStep {
}

or

ourStep('value') {
}

With declarative pipeline, it doesn't seem to work the same way. Trying to use

ourStep {
}

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 7: Missing required parameter: "param" @ line 7, column 9.
           ourStep {
           ^

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:127)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)


Is there a way to have a similar behavior, or is it definitely something forbidden in the declarative pipeline?

Thanks,

Julien Henry | SonarSource

Developer

https://sonarsource.com

Baptiste Mathus

unread,
Mar 19, 2018, 7:16:26 AM3/19/18
to Jenkins Developers
Though it's possibly a bug, why use @DataBoundConstructor instead of @DataBoundSetter? I generally use the constructor for required params, and setters for optional ones.

--
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 jenkinsci-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEyhW9%2B1txF-MgvbX35Bs5y4J906W7rDyo6OYn0kbYV8Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Andrew Bayer

unread,
Mar 19, 2018, 7:51:13 AM3/19/18
to jenkin...@googlegroups.com
So, there is a ticket for this in Declarative - https://issues.jenkins-ci.org/browse/JENKINS-42772 - but I have yet to be happy with a solution. I can’t, so far as I’m aware, check the DescribableModel for the class in question, and see it’s got a sole required argument *and* see that it could be null. Is annoying.

The reason for this use case, btw, is so you can call step(“foo”) without naming the parameter - that only works with a @DataBoundConstructor.

A.

To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.

--
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 jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANWgJS7ytEyvQdhHXt7-kxqfxRqOm7W2YnV%3DW6%2BnM9gywAcfEw%40mail.gmail.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages