Plugins 詹金斯插件。根动作。单独窗口中的index.jelly
我正在编写一个简单的插件,并被迫创建一个RootAction,它显示一个页面(index.jelly),需要一些额外的值来确认并执行该方法 我的问题是,index.jelly文件总是显示在空白窗口中。 但我确实需要像往常一样将其包含在主表的Jenkins模板中 我似乎不明白为什么会这样 有什么想法吗 RestartJksLink.javaPlugins 詹金斯插件。根动作。单独窗口中的index.jelly,plugins,jenkins,jelly,Plugins,Jenkins,Jelly,我正在编写一个简单的插件,并被迫创建一个RootAction,它显示一个页面(index.jelly),需要一些额外的值来确认并执行该方法 我的问题是,index.jelly文件总是显示在空白窗口中。 但我确实需要像往常一样将其包含在主表的Jenkins模板中 我似乎不明白为什么会这样 有什么想法吗 RestartJksLink.java package org.jenkinsci.plugins.tomcat_app_restart; import hudson.Extension; imp
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-inside: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插件开发新手,这将帮助我了解很多东西
问候您。这个演示(rootaction示例插件)帮助很大。您可以阅读它
将
标记和
标记添加到index.jelly文件中
并包括侧面板:
- 将构建传递给操作(通过构造函数的参数)
- 可以从从继承自BuildStepCompatibilityLayer类的perform方法的参数中检索生成(通过扩展Publisher)
- 在Action类中创建getBuild()方法
- 将
标记添加到构建中
<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>
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;
}
}
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;
}
}
Java操作类示例:
<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>
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;
}
}
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;
}
}
包tryPublisher.tryPublisher;
导入hudson.model.Action;
导入hudson.model.AbstractBuild;
公共类ExampleAction实现操作{
抽象构建;
公共示例操作(AbstractBuild){
this.build=build;
}
@凌驾
公共字符串getIconFileName(){
返回“/plugin/action.png”;
}
@凌驾
公共字符串getDisplayName(){
返回“ExampleAction”;
}
@凌驾
公共字符串getUrlName(){
返回“ExampleActionUrl”;
}
公共抽象构建getBuild(){
返回这个.build;
}
}
Java发布者类示例:
<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>
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;
}
}
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;
}
}
包tryPublisher.tryPublisher;
导入java.io.IOException;
进口哈德逊发射器;
导入hudson.model.AbstractBuild;
导入hudson.model.BuildListener;
导入hudson.tasks.BuildStepMonitor;
导入hudson.tasks.Publisher;
公共类ExamplePublisher扩展了Publisher{
@凌驾
public BuildStepMonitor getRequiredMonitorService(){
返回BuildStepMonitor.NONE;
}
@凌驾
公共布尔执行(AbstractBuild-build,Launcher-Launcher,
BuildListener(侦听器)引发InterruptedException,IOException{
build.getActions().add(新的ExampleAction(build));
返回true;
}
}
.jelly文件必须位于插件项目的正确资源映射中。在与实现操作的Java类的名称相同的映射中。果冻的名字也很重要