I created this class 

package notifier;

import hudson.Extension;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.tasks.*;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
 * Created by giladba on 8/31/2015.
 */
public class BuildNotifier extends Notifier {
    private final String to;

    @DataBoundConstructor
    public BuildNotifier(String to){
        if(to==null)
            to="";
        this.to=to;
    }

    @Override
    public boolean perform(AbstractBuild build, Launcher launcher, 
BuildListener listener) {
       // build.getEnvVars()["myVar"]
       // listener.getLogger().println("Build Success Notifier Finished.");
        return true;
    }

    @Override
    public BuildStepMonitor getRequiredMonitorService() {
        return null;
    }

    public String getTo() {
        return to;
    }

    @Override
    public DescriptorImpl getDescriptor() {
        return (DescriptorImpl)super.getDescriptor();
    }

    @Extension
    public static final class DescriptorImpl extends 
BuildStepDescriptor<Publisher> {

        public DescriptorImpl() {
            load();
        }

        @Override
        public boolean isApplicable(Class<? extends AbstractProject> jobType) {
            return true;
        }

        @Override
        public boolean configure(StaplerRequest req, JSONObject formData) 
throws FormException {
            save();
            return super.configure(req,formData);
        }

        @Override
        public String getDisplayName() {
            return "Build Success Email";
        }
    }

}



I added the config.jelly (it works, i see the UI in the post build) :

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" 
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
    <!--
      This jelly script is used for per-project configuration.

      See global.jelly for a general discussion about jelly script.
    -->

    <!--
      Creates a text field that shows the value of the "name" property.
      When submitted, it will be passed to the corresponding constructor 
parameter.
    -->
    <f:entry title="To" field="to">
        <f:textarea />
    </f:entry>
</j:jelly>



But when I run the build I get this Exception : 
java.lang.NullPointerException
at 
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:770)
at 
hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:734)
at hudson.model.Build$BuildExecution.post2(Build.java:183)
at 
hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:683)
at hudson.model.Run.execute(Run.java:1770)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:89)
at hudson.model.Executor.run(Executor.java:240)

which refers to this code from jenkins (im guessing that in the last line 
mon=null):

/**
 * Calls a build step.
 */
protected final boolean perform(BuildStep bs, BuildListener listener) throws 
InterruptedException, IOException {
    BuildStepMonitor mon;
    try {
        mon = bs.getRequiredMonitorService();
    } catch (AbstractMethodError e) {
        mon = BuildStepMonitor.BUILD;
    }
    Result oldResult = AbstractBuild.this.getResult();
    for (BuildStepListener bsl : BuildStepListener.all()) {
        bsl.started(AbstractBuild.this, bs, listener);
    }
    boolean canContinue = mon.perform(bs, AbstractBuild.this, launcher, 
listener);


What am i missing here?

-- 
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/62a711b2-5c5b-4df0-9889-47a78d0646c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to