How to pass a class instance in a jenkins pipeline script?

21 views
Skip to first unread message

touseef

unread,
Apr 10, 2019, 12:14:31 AM4/10/19
to Jenkins Users
I have a pipeline  compliant test plugin.in a  @databoundConstructor i have to pass an instance of another class Input (consisting of n number of variables to be taken as input)


@Symbol("forget")
@Extension
public class ForgetBuilder extends Builder implements SimpleBuildStep {
    private final String what;
    @CheckForNull
    public String stuff;
    public Boolean checkbox;
    public Input Input;
    @DataBoundConstructor
    public ForgetBuilder(String what,String stuff,boolean checkbox, Input Input) {
        this.what = what;
        this.stuff=stuff;
        this.checkbox=checkbox;
        this.Input=Input;
    }

    public Input getInput() {
return Input;
}

public Boolean getCheckbox() {
return checkbox;
}

public String getWhat() {
        return what;
    }
    @Nonnull
    public String getStuff() {
        return stuff == null ? DescriptorImpl.defaultStuff : stuff;
    }


    @Override
    public void perform(Run build,
                        FilePath workspace,
                        Launcher launcher,
                        TaskListener listener) throws InterruptedException, IOException {
        listener.getLogger().println("What was " + what + "?");
        listener.getLogger().println("stuff was " + stuff + "?");
        listener.getLogger().println("checkbox was " + checkbox + "?");
      
        
        
    }
    
I an able to write the pipeline script by which i can pass the arguments like string ,boolean etc.But im not sure how to pass the instance of another class in script


//script works fine with primitive variable ,can any please help me in how to pass the instance of another class after setting it variable to the below script
step([$class: 'ForgetBuilder', what: 'first string arg', stuff: 'Secong string arg' ,checkbox:true])
Message has been deleted

Slide

unread,
Apr 10, 2019, 8:32:35 AM4/10/19
to Jenkins User Mailing List
If you mark the descriptors for the classes with @Symbol, you can use a shorthand to access the steps. You would need to make your Input class a Describable and add a descriptor for it to work for that.

On Tue, Apr 9, 2019 at 9:51 PM touseef <tousee...@gmail.com> wrote:
I figured it out.Posting the solution


    step([$class: 'ForgetBuilder', what: 'first string arg', stuff: 'Secong string arg' ,checkbox:true,Input: [$class: 'Input',ideSelectionToUse:"value from instance class"]])  

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/e2426331-1417-41de-9720-b3290f6b19d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Reply all
Reply to author
Forward
0 new messages