如何在日志文件中解析'stapler-class'被弃用的警告?

时间:2015-03-27 08:50:07

标签: jenkins-plugins

这是我第一次尝试创建Jenkins插件,我担心我会使用一种过时的技术来创建插件。

感激地收到任何建议!

config.jelly

<?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">
  <f:entry/><!-- just for help.html -->
  <f:entry title="Application" field="applicationId">
    <f:textbox />
  </f:entry>
  <f:entry title="Use Jenkins BuildNumber" field="useJenkinsBuildNumber">
    <f:checkbox />
  </f:entry>  
</j:jelly>

GetReleaseNumberBuildStep.java

package com.example;

import hudson.Launcher;
import hudson.Extension;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.AbstractProject;
import hudson.tasks.Builder;
import hudson.tasks.BuildStepDescriptor;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import com.example.TestPlugin.TestPluginDescriptor;

import jenkins.model.Jenkins;

public class GetReleaseNumberBuildStep extends Builder {
    private final String applicationId;
    private final boolean useJenkinsBuildNumber;

    @DataBoundConstructor
    public GetReleaseNumberBuildStep(String applicationId, String workflowId, boolean useJenkinsBuildNumber) {
        this.applicationId = applicationId;
        this.useJenkinsBuildNumber = useJenkinsBuildNumber;
    }

    public String getApplicationId() {
        return applicationId;
    }

    public boolean getUseJenkinsBuildNumber() {
        return useJenkinsBuildNumber;
    }

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

        listener.getLogger().println("Set environment variable TEST_RELEASE");

        VariableInjectionAction action = new VariableInjectionAction("TEST_RELEASE", "test_release_value");
        build.addAction(action);

        return true;
    }

    public TestPluginDescriptor getSharedDescriptor() {
        return (TestPluginDescriptor)Jenkins.getInstance().getDescriptorOrDie(TestPlugin.class);
    }

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

        public DescriptorImpl() {
            load();
        }

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

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

        @Override
        public String getDisplayName() {
            return "Get Latest Release Number";
        }

    }
}

0 个答案:

没有答案