1.導入依賴
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>2.3.17</version>
</dependency>
2.連接
public static final String JIRA_URL = "http://jira.ccic-net.com.cn"; //jira請求地址
public static final String JIRA_USERNAME = "userName"; //jira賬號
public static final String JIRA_PASSWORD = "password"; //jira密碼
3.常用jira語句
/**
* 自定義url語句
* @param url
* @return
*/
public static Object getCustomUrl(String url){
try {
HttpResponse<JsonNode> response = Unirest.get(url)
.basicAuth(JIRA_USERNAME, JIRA_PASSWORD)
.header("Accept", "application/json")
.asJson();
return response.getBody();
}catch (Exception e){
e.printStackTrace();
return "error";
}
}
/**
* 獲取儀表板
* @param url
* @return
*/
public static String getDashboard(String url){
try {
HttpResponse<JsonNode> response = Unirest.get(url+"/rest/api/2/dashboard")
.basicAuth(JIRA_USERNAME, JIRA_PASSWORD)
.header("Accept", "application/json")
.asJson();
return response.getBody().toString();
}catch (Exception e){
e.printStackTrace();
return "error";
}
}
/**
* 取得問題
* @param url
* @param issueIdOrKey
* @return
*/
public static String getIssue(String url,String issueIdOrKey){
try {
HttpResponse<JsonNode> response = Unirest.get(url+issueIdOrKey) // /rest/api/2/issue/{issueIdOrKey}
.basicAuth(JIRA_USERNAME, JIRA_PASSWORD)
.header("Accept", "application/json")
.asJson();
return response.getBody().toString();
}catch (Exception e){
e.printStackTrace();
return "error";
}
}
/**
* 獲取附件文件
* @param id
* @return
*/
public static String getAccessory(String id){
try {
HttpResponse<JsonNode> response = Unirest.get(JIRA_URL+"/rest/api/2/attachment/"+id)
.basicAuth(JIRA_USERNAME, JIRA_PASSWORD)
.header("Accept", "application/json")
.asJson();
JSONObject accessoryJSON = JSON.parseObject(response.getBody().toString());
return accessoryJSON.get("content").toString();
}catch (Exception e){
e.printStackTrace();
return "error";
}
}
4.jira restApi參考地址:https://docs.atlassian.com/software/jira/docs/api/REST/7.11.0/#api/2/application-properties-getAdvancedSettings