使用插件轻松获取jenkins构建数据

使用插件获取Build数据

下载插件

https://github.com/jenkinsci/...

下载这个插件,cd到下载目录下,编译插件,

使用:mvn install 或者 mvn package命令。

编译完成后会在插件目录下生成target目录,可以看到

使用插件轻松获取jenkins构建数据_第1张图片
打开安装好的jenkins

使用插件轻松获取jenkins构建数据_第2张图片

使用插件轻松获取jenkins构建数据_第3张图片

QQWsOK.png

使用插件轻松获取jenkins构建数据_第4张图片

上传刚编译好的 statistics-gatherer.hpi 插件安装。

打开系统设置。

使用插件轻松获取jenkins构建数据_第5张图片

会发现多了一个Statistics Gatherer模块

使用插件轻松获取jenkins构建数据_第6张图片

使用插件轻松获取jenkins构建数据_第7张图片

打开高级配置,将http勾选。

使用插件轻松获取jenkins构建数据_第8张图片

使用Java接收build数据Demo

@RestController
@RequestMapping(value = "/jenkins", produces = "application/json;charset=UTF-8")
public class BuildDataController{
@RequestMapping("/buildData")
    public void buildData(HttpServletRequest request) throws IOException {
        BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "utf-8"));
        StringBuilder responseStrBuilder = new StringBuilder();
        String inputStr;
        while ((inputStr = streamReader.readLine()) != null) {
            responseStrBuilder.append(inputStr);
        }
        BuildData build = JSON.parseObject(responseStrBuilder.toString(), BuildData.class);
    }
}

@Setter
@Getter
public class BuildData {
    private Date startTime;

    private Date endTime;

    private String startedUserName;

    private String fullJobName;

    private String jobName;

    private String result;

    private Integer id;

    private String buildCause;

    private String buildUrl;
}

运行程序,在jenkins中Build URL填入接口地址。

使用插件轻松获取jenkins构建数据_第9张图片

构建jenkins项目,就可以获得了jenkins build数据。

使用插件轻松获取jenkins构建数据_第10张图片

同理可以获取Queue、Project/Job、Build Steps数据,返还的数据具体格式可以去 https://github.com/jenkinsci/... 查看。

你可能感兴趣的:(javajenkins)