0

私は単純なプラグインを作成しており、ページ (index.jelly) を表示する RootAction を作成する必要があり、メソッドを確認して実行するために追加の値が必要です。

私の問題は、 index.jelly ファイルが常に空白のウィンドウに表示されることです。しかし、いつものように、メイン テーブルの Jenkinstemplate 内に含める必要があります。

なぜこれが起こっているのか理解できないようです。

何か案は?

RestartJksLink.java

package org.jenkinsci.plugins.tomcat_app_restart;

import hudson.Extension;
import hudson.model.ManagementLink;

/**
 *
 *
 * @author [...]
 */
@Extension
public class RestartJksLink extends ManagementLink {
    @Override
    public String getIconFileName() {
        return "/plugin/tomcat-app-restart/images/restart.png";
    }

    @Override
    public String getUrlName() {
        return "jksrestart";
    }

    @Override
    public String getDescription() {
       return "Restart your Jenkins-Application on Tomcat";
    }

    public String getDisplayName() {
        return "Restart Jenkins-App on Tomcat";
    }
}

RestartJksRootAction.java

package org.jenkinsci.plugins.tomcat_app_restart;

import java.io.IOException;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;

import jenkins.model.Jenkins;
import hudson.Extension;
import hudson.model.RootAction;
import hudson.util.FormValidation;

@Extension
public class RestartJksRootAction implements RootAction {
    public String getDisplayName() {
        return "Restart Jenkins on Tomcat";
    }

    public String getIconFileName() {
        if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
          return null;
        }

        if (!Jenkins.getInstance().getLifecycle().canRestart()) {
          return null;
        }

        return "/plugin/tomcat-app-restart/images/restart.png";
    }

    public String getUrlName() {
        return "jksrestart";
    }

    public FormValidation doJksRestart() {
        Authenticator.setDefault (new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication ("admin", "admin".toCharArray());
            }
        });

        URL url;
        try {
            url = new URL("http://localhost:8888/manager/text/start?path=/jenkins");
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            System.out.println("" + connection.getResponseMessage());

            return FormValidation.ok("Success");
        } catch (IOException e) {

            return FormValidation.error("Client error: " + e.getMessage());
        }
    }
}

index.jelly 内部: resources.org.jenkinsci.plugins.tomcat_app_restart.RestartJksRootAction

<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" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
  <f:validateButton
   title="${%Restart Jenkins}" progress="${%Restarting...}"
   method="JksRestart" with="" />
</j:jelly>

君たちありがとう!

私はjenkinsプラグイン開発に慣れていないので、理解するのに大いに役立ちます.

敬具。

4

2 に答える 2

1

<l:main-panel>タグと<l:layout norefresh="true">タグを index.jelly ファイルに追加します。

サイド パネルを含めます。

  • ビルドを Action に渡します (コンストラクターのパラメーターを介して)
    • ビルドは、BuildStepCompatibilityLayer クラスから継承された perform メソッドのパラメーターから取得できます (Extended Publisher による)。
  • Action クラスに getBuild() メソッドを作成する
  • <st:include it="${it.build}" page="sidepanel.jelly" />ビルドでタグを追加します

ゼリーの例 (index.jelly):

<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" xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
    <l:layout norefresh="true">
        <st:include it="${it.build}" page="sidepanel.jelly" />
        <l:main-panel>
            <f:validateButton title="${%Restart Jenkins}" progress="${%Restarting...}" method="JksRestart" with="" />
        </l:main-panel>
    </l:layout>
</j:jelly>

Java Action クラスの例:

package tryPublisher.tryPublisher;

import hudson.model.Action;
import hudson.model.AbstractBuild;


public class ExampleAction implements Action {
    AbstractBuild<?,?> build;

    public ExampleAction(AbstractBuild<?,?> build) {
        this.build = build;
    }

    @Override
    public String getIconFileName() {
        return "/plugin/action.png";
    }

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

    @Override
    public String getUrlName() {
        return "ExampleActionUrl";
    }

    public AbstractBuild<?,?> getBuild() {
        return this.build;
    }
}

Java Publisher クラスの例:

package tryPublisher.tryPublisher;

import java.io.IOException;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.Publisher;

public class ExamplePublisher extends Publisher {

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

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

        build.getActions().add(new ExampleAction(build));

        return true;
    }

}

.jelly ファイルは、プラグイン プロジェクトの適切なリソース マップにある必要があります。Action を実装する Java クラスの名前と同じ名前のマップ内。.jelly の名前も重要です。

于 2014-12-10T11:19:56.457 に答える
1

このデモ (rootaction-example-plugin) は大いに役立ちました。

https://github.com/gustavohenrique/jenkins-plugins/tree/master/rootaction-example-plugin

于 2014-09-27T06:27:34.303 に答える