Jenkins 插件开发——build页面右侧创建页面&jenkin自身bug一例

需求如下:

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将无法显示页面,如下图。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值