jenkins自动发送jira项目不同状态bug数量
在工作中有这样一种想法:bug统计在jira中,而为了及时的告知各位产品开发项目bug的解决数量,我要实现jenkins定时发送钉钉bug各种状态的数量
1、前期思路,操作jira查询,抓取接口,通过解析接口获取bug数,最后发现不可行,因为jira没有单独的接口,数据库不对外暴露
2、最后通过ui自动化+http+钉钉api实现
图13、pom.xml中引入:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.3</version>
</dependency>
</dependencies>
4、java发送钉钉通知的方法抽出公用的数据
title:标题 content:消息体 url:点击跳转链接 token:对应的钉钉token
private void testReport(String title ,String content,String url,String token) {
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(token);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
String test="{\"msgtype\": \"link\",\"link\": {\"text\":\""+content+"\",\"title\": \""+title+"\", \"picUrl\": \"\", \"messageUrl\":\""+url+"\"}}";
System.out.println(test);
StringEntity se = new StringEntity(test, "utf-8");
httppost.setEntity(se);
HttpResponse response;
try {
response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode()== HttpStatus.SC_OK){
String result= EntityUtils.toString(response.getEntity(), "utf-8");
System.out.println(result);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
5、webdriver去获取jira页面的元素,优先判断登录状态,其次通过筛选拿到每种bug数的链接
图2 图3