Snippet generator for a SCMStep with one argument constructor generates incorrect groovy

27 views
Skip to first unread message

Lakshmi Narasimhan Vaikuntam

unread,
Aug 10, 2015, 10:30:23 AM8/10/15
to Jenkins Developers
 I have implemented a custom step extending SCMStep. The step's constructor takes one non primitive type as an argument.

public class A {
 
@DataBoundConstructor
 
public A( String arg1, String arg2) {
 
}
}

@Extension
public class MyStep{
 
@DataBoundConstructor
 
public MyStep(A arg)  {
 
}

   
public static class MyStepDescriptor extends SCMStepDescriptor {
   
@Override
   
public String getFunctionName() {
       
return "mystep";
   
}
 
}
}


I have added a config.jelly file for MyStep. When using the snippet generator for this step, I get the following groovy
  mystep([arg1:"", arg2:""])
When running the workflow job with this script,  the arg parameter in the MyStep constructor is null.

I also noticed that adding another dummy argument to MyStep constructor generates the groovy with the parameter name.

Is there any way to overcome this problem with the snippet generator without adding a dummy parameter? This seems to be an issue only with non primitive types because I can invoke git step as git "repo_path" and it works correctly.

Jesse Glick

unread,
Aug 10, 2015, 1:46:13 PM8/10/15
to Jenkins Dev
On Mon, Aug 10, 2015 at 10:30 AM, Lakshmi Narasimhan Vaikuntam
<vaikuntam....@gmail.com> wrote:
> public class A {

You must: `extends AbstractDescribableImpl<A>` and create `A/config.jelly`.

> @DataBoundConstructor
> public A( String arg1, String arg2) {
> }

You also need public getters for these.

> @Extension

`@Extension` goes on the descriptor, not the describable.

> public class MyStep{

`extends SCMStep`?

> @DataBoundConstructor
> public MyStep(A arg) {
> }

Again need a getter for `arg`.

> Is there any way to overcome this problem with the snippet generator without
> adding a dummy parameter?

I suspect this is the same problem as filed in JENKINS-29711. There is
no workaround other than documenting that in current Workflow releases
the required syntax is

mystep arg: [arg1: '…', arg2: '…']

Jesse Glick

unread,
Aug 10, 2015, 1:53:40 PM8/10/15
to Jenkins Dev
By the way please come to my Office Hour on Wednesday if you can.

https://wiki.jenkins-ci.org/display/JENKINS/Office+Hours
Reply all
Reply to author
Forward
0 new messages