1

IP電源タップデバイスと通信する単純なJenkinsプラグインを作成しようとしていますが、いくつかの問題が発生しました。私はドキュメントを掘り下げましたが、せいぜいまばらなようです。

私の理論は、記述子が関連付けられたパブリッシャーを作成することでした。記述子は、Beanオブジェクト(params)を介して繰り返し可能な形式を取り、レコーダーで使用できるようにします。

実際に起こっているように見えることは次のとおりです。

Caused by: net.sf.json.JSONException: Error while setting property=data type interface java.util.List
at net.sf.json.JSONObject.toBean(JSONObject.java:577)
at net.sf.json.JSONObject.toBean(JSONObject.java:383)
at net.sf.json.JSONObject.toBean(JSONObject.java:250)
at hudson.tools.JDKInstaller$JDKList.toList(JDKInstaller.java:612)
at hudson.tools.JDKInstaller$DescriptorImpl.getInstallableJDKs(JDKInstaller.java:588)
... 237 more
Caused by: java.lang.NullPointerException
at net.sf.json.JSONObject$MethodProperty.isWritable(JSONObject.java:311)
at net.sf.json.JSONObject.toBean(JSONObject.java:429)
... 241 more

これがparamsクラスです

package com.mb;


import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.io.Serializable;

@ExportedBean
public class PlugParamters extends AbstractDescribableImpl<PlugParamters> implements Serializable {

private final String buildState;
private final String plugId;
private final int plugAction;

@DataBoundConstructor
public PlugParamters(String buildState, String plugId, int plugAction) {
this.buildState = buildState;
this.plugId = plugId;
this.plugAction = plugAction;
}

@Exported
public String getBuildState() {
return buildState;
}

@Exported
public String getPlugId() {
return plugId;
}

@Exported
public int getPlugAction() {
return plugAction;
}

@Extension
public static class DescriptorImpl extends Descriptor<PlugParamters> {

public DescriptorImpl() {
    super(PlugParamters.class);
}

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

}

そして最後に:

package com.mb;


import hudson.Extension;
import hudson.Launcher;
import hudson.model.*;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;
import hudson.tasks.Recorder;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;

import javax.servlet.ServletException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class IPPowerPublisher extends Recorder {

public IPPowerPublisher() {
}

@Override
public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) {

return true;
}

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


public BuildStepMonitor getRequiredMonitorService() {
return BuildStepMonitor.NONE;
}

private boolean oneOrMoreBuildsFailing(List<Project> projects) {

boolean oneOrMoreBuildsFailing = false;
for (Project project : projects) {
    Result projectLatestBuildResult = project.getLastBuild().getResult();

    if (!(projectLatestBuildResult.isBetterOrEqualTo(Result.SUCCESS) || !projectLatestBuildResult.equals(Result.NOT_BUILT))) {
        oneOrMoreBuildsFailing = true;
        break;
    }
}

return oneOrMoreBuildsFailing;
}



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

public List<PlugParamters> getPlugParamters() {
    return plugParamters;
}

public void setPlugParamters(List<PlugParamters> plugParamters) {
    this.plugParamters = plugParamters;
}

private List<PlugParamters> plugParamters = new ArrayList<PlugParamters>();
private String host = "";

public FormValidation doCheckHost(@QueryParameter String value) throws IOException, ServletException {

    if (value != null && value.length() == 0)
        return FormValidation.error("Please set a host name or IP address");

    return FormValidation.ok();
}

@Override
public String getDisplayName() {
    return "Continuous Integration Feedback";
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws hudson.model.Descriptor.FormException {
    host = formData.getString("host");

    //plugParamters = req.bindParametersToList(PlugParamters.class, "");

    save();
    return super.configure(req, formData);
}

public String getHost() {
    return host;
}

public void setHost(String host) {
    this.host = host;
}


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

}
4

0 に答える 0