Plugin to add a custom build step.

67 views
Skip to first unread message

Kul Bhushan Srivastava

unread,
Oct 15, 2016, 11:36:51 AM10/15/16
to Jenkins Developers

I gone through the following URL https://wiki.jenkins-ci.org/display/JENKINS/Create+a+new+Plugin+with+a+custom+build+Step and implemented the same to develop my own custom plugin but the same is not achieved.

Jenkins version : 1.651.1

Please help.

Daniel Beck

unread,
Oct 15, 2016, 1:00:12 PM10/15/16
to jenkin...@googlegroups.com

> On 15.10.2016, at 17:36, Kul Bhushan Srivastava <cool...@gmail.com> wrote:
>
> the same is not achieved

You need to provide much more information than this.

http://www.catb.org/~esr/faqs/smart-questions.html#beprecise

Kul Bhushan Srivastava

unread,
Oct 17, 2016, 2:23:14 AM10/17/16
to Jenkins Developers, m...@beckweb.net
Hi Daniel,

Thanks for your response.

I am using the sample java code demonstrated in the following link https://wiki.jenkins-ci.org/display/JENKINS/Create+a+new+Plugin+with+a+custom+build+Step
to build my custom build step. POM.xml is same as described here except parent section version tag. In my case it is 1.420 instead of 1.400

I have did this change to resolve one of the ClassNotFound exception while using version 1.400

I have build the maven project using https://wiki.jenkins-ci.org/display/JENKINS/Plugin+tutorial for my Eclipse IDE.

The java code looks like

import hudson.task.Builder;
import org.kohsuke.stapler.DataBoundConstructor;

public class BuildStepCreation extends Builder{
    private final String task;

    @DataBoundConstructor
    public BuildStepCreation(String task) {
        this.task = task;
    }
   
    public String getTask() {
        @Extension
        public static class Descriptor extends BuildStepDescriptor<Builder> {

            @Override
            public boolean isApplicable(Class<? extends AbstractProject> jobType) {
                return FreeStyleProject.class.isAssignableFrom(jobType);
            }

            @Override
            public String getDisplayName() {
                return "Job Orchestration";
            }
        }
    }
}

Daniel Beck

unread,
Oct 17, 2016, 4:06:31 AM10/17/16
to jenkin...@googlegroups.com

> On 17.10.2016, at 08:23, Kul Bhushan Srivastava <cool...@gmail.com> wrote:
>
> The java code looks like

Follow the rest of the instructions. You're not done after the first listing, a third into the first section of the tutorial.

Daniel Beck

unread,
Oct 17, 2016, 4:08:56 AM10/17/16
to jenkin...@googlegroups.com

> On 17.10.2016, at 08:23, Kul Bhushan Srivastava <cool...@gmail.com> wrote:
>
> public String getTask() {
> @Extension
> public static class Descriptor extends BuildStepDescriptor<Builder> {

Correction, the descriptor (second listing) is there, but not done correctly.

The static nested class needs to be a 'sibling' of getTask(), not a 'child'.

Message has been deleted
Message has been deleted
Message has been deleted

Daniel Beck

unread,
Oct 18, 2016, 7:15:16 AM10/18/16
to jenkin...@googlegroups.com

> On 17.10.2016, at 20:07, Kul Bhushan Srivastava <cool...@gmail.com> wrote:
>
> Please suggest.

I don't know what else is wrong. Compare what you did with the mvn hpi plugin archetype, it basically does exactly what you're doing, and it works.

mvn -U org.jenkins-ci.tools:maven-hpi-plugin:create

FWIW it seems insane to upload plugins you don't even know are working to Jenkins. Just debug them locally. You won't have to restart Tomcat then to apply changes.

Kul Bhushan Srivastava

unread,
Oct 24, 2016, 4:13:14 AM10/24/16
to Jenkins Developers, m...@beckweb.net
Thanks for suggestions. I am able to build a custom build step now successfully. Final code looks like this.

JAVA File

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;

public class BuildStepCreator extends Builder {
   
    private String text, text1, text2;
   
    public String getText(){
        return text;
    }
    public String getText1(){
        return text1;
    }
    public String getText2(){
        return text2;
    }
   

    @DataBoundConstructor
    public BuildStepCreator(OptinalTextBlock enableText, OptinalTextBlock1 enableText1, OptinalTextBlock2 enableText2) {
        this.text = (enableText != null) ? enableText.text : null;
        this.text1 = (enableText != null) ? enableText1.text1 : null;
        this.text2 = (enableText != null) ? enableText2.text2 : null;
    }

    public static class OptinalTextBlock {
        private String text;
        @DataBoundConstructor
        public OptinalTextBlock(String text) {
            this.text = text;
        }
    }
    public static class OptinalTextBlock1 {
        private String text1;
        @DataBoundConstructor
        public OptinalTextBlock1(String text1) {
            this.text1 = text1;
        }
    }
    public static class OptinalTextBlock2 {
        private String text2;
        @DataBoundConstructor
        public OptinalTextBlock2(String text2) {
            this.text2 = text2;
        }
    }

    @Override
    public boolean perform(hudson.model.AbstractBuild build, hudson.Launcher launcher, hudson.model.BuildListener listener) {
        listener.getLogger().println("OptionalBlockSampleBuilder " + text);
        return true;
    }

   
    @Extension
    public static final class DescriptorImpl extends BuildStepDescriptor<Builder>{
       
        /*public FormValidation doCheckTask(@QueryParameter String value){
            try{
                if(value.equalsIgnoreCase(null) || value.equalsIgnoreCase("")){
                    return FormValidation.error("Invalid Details.");
                }
            }catch(Exception e){
                return FormValidation.error("Error validating the form details.");
            }
            return FormValidation.ok();
        }
       
        public FormValidation doCheckGoal(@QueryParameter String value){
            try{
                Integer.parseInt(value);
            }catch(Exception e){
                return FormValidation.error("Please provide integer in the Goal.");
            }
            return FormValidation.ok();
        }*/


        @Override
        public boolean isApplicable(Class<? extends AbstractProject> jobType) {
            // TODO Auto-generated method stub
            return true;
        }

        @Override
        public String getDisplayName() {
            // TODO Auto-generated method stub
            return "Job Orchectration";
        }
       
    }
}

config.jelly

<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
  <f:block>
        <f:optionalBlock name="enableText" title="Test Execution - PresetUp" checked="${instance.text != null}">
            <f:entry title="Command" field="text">
                <f:textarea />
            </f:entry>
        </f:optionalBlock>
  </f:block>
  <f:block>
        <f:optionalBlock name="enableText1" title="Execute Test" checked="${instance.text1 != null}">
            <f:entry title="Command" field="text1">
                <f:textarea />
            </f:entry>
        </f:optionalBlock>
  </f:block>
  <f:block>
        <f:optionalBlock name="enableText2" title="Post-Run Cleanup" checked="${instance.text2 != null}">
            <f:entry title="Command" field="text2">
                <f:textarea />
            </f:entry>
        </f:optionalBlock>
  </f:block>
</j:jelly>

Kul Bhushan Srivastava

unread,
Oct 24, 2016, 4:18:51 AM10/24/16
to Jenkins Developers, m...@beckweb.net
Hi,

I am willing to put three windows batch command option (one in each optionalblock segment) in custom build step which I have developed.

Please find my config,jelly and java code below. What changes I need to done to achieve the same.
Reply all
Reply to author
Forward
0 new messages