需求如下:
build页面右侧创建页面,如下图
左侧点击后,右侧对应显示内容
首先这个页面是一个Action
1、Jelly Example (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>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
</l:main-panel>
</l:layout>
</j:jelly>
2、Java Action class example:
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;
}
}
3、Java Publisher class example:
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));//添加Action,该方法已废弃,但可用
return true;
}
}
Jenkins BUG:详情见https://issues.jenkins-ci.org/browse/JENKINS-30855
如果之前没有这么实现,后来使用该方法只能用于新建的build,之前的build将无法显示页面,如下图。