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. On Mon, Mar 19, 2018 at 7:16 AM Baptiste Mathus <[email protected]> wrote: > 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. > > 2018-03-19 11:48 GMT+01:00 Julien HENRY <[email protected]>: > >> 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 >> >> -- >> 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/CAD9wyxEyhW9%2B1txF-MgvbX35Bs5y4J906W7rDyo6OYn0kbYV8Q%40mail.gmail.com >> <https://groups.google.com/d/msgid/jenkinsci-dev/CAD9wyxEyhW9%2B1txF-MgvbX35Bs5y4J906W7rDyo6OYn0kbYV8Q%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- > 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/CANWgJS7ytEyvQdhHXt7-kxqfxRqOm7W2YnV%3DW6%2BnM9gywAcfEw%40mail.gmail.com > <https://groups.google.com/d/msgid/jenkinsci-dev/CANWgJS7ytEyvQdhHXt7-kxqfxRqOm7W2YnV%3DW6%2BnM9gywAcfEw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAPbPdObVxiWqxMzacewXc-O7vRhV1zv7Yd_OMp%2BffrufyVmDAw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
