Я пишу простой плагин и вынужден создать RootAction, который отображает страницу (index.jelly) и требует некоторых дополнительных значений для подтверждения и последующего выполнения метода.
Моя проблема в том, что файл 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, это поможет мне многое понять.
С уважением.