是否有人知道如何使用JIRA、java、REST客户端api或其他方式使用java访问JIRA敏捷sprint。
1)我试图检索JIRA数据(项目、sprint、问题等)。我需要一种方式来查询项目,冲刺与不同的过滤器以及。我想JRJC无法获得敏捷数据。对于整个JIRA数据是否有一站式解决方案?
2) JIRA在其文档中提供了2种类型的Api : REST、api和Java。什么时候使用这些
发布于 2016-06-14 08:51:28
https://docs.atlassian.com/jira/REST/latest/
请注意,您可以使用以下内容获取项目信息:https://docs.atlassian.com/jira/REST/latest/#api/2/project
关于sprint信息-你能从JQL那里得到你需要的信息吗?你能去问题>搜索问题并使用基本搜索吗?在这里,在“更多”选项下,您将看到可以指定要筛选的Sprint。
当您添加/删除sprint时,您将看到URL发生变化。例如,如果我选择看到Sprint 1和Sprint 6中的所有问题类型,那么我的JQL如下所示:
?jql=Sprint%20in%20(227%2C%20229)请注意,这些是sprint ids。
现在,您可以使用如下的搜索调用rest:
https://jira.domain.com/rest/api/2/search?jql=Sprint%20in%20(227%2C%20229)这里有更多详细信息:https://docs.atlassian.com/jira/REST/latest/#api/2/search
( b)如果您可以使用过滤器获取您想要的信息,您可以简单地保存过滤器并使用rest调用过滤器
https://jira.domain.com/rest/api/2/filter/{filter-id}这里有更多详细信息:https://docs.atlassian.com/jira/REST/latest/#api/2/filter-getFilter
Jira的Java或REST客户机是一组不受支持的库,如果您特别希望使用Java进行这些rest调用,可以使用它。当然,您可以使用泽西岛或者其他您想要调用的东西,但是Java客户端提供了一些可能有用的库。
发布于 2016-06-23 05:43:07
试试这个..。我用了下面的代码,
private int setSprint(String sprint, String key, String boardId) {
String _jiraUser = applicationProperties.get(Constants.JIRAUSER);
String _jiraPwd = applicationProperties.get(Constants.JIRAPWD);
String auth = new String(Base64.encode(_jiraUser + ":" + _jiraPwd));
String agileURL = applicationProperties.get(Constants.JIRAURL)
+ "/rest/agile/1.0/board/" + boardId + "/sprint";
int sprintId = invokeGetMethod(auth, agileURL, sprint);
// Constants.REPORT.info(sprintId);
String issueURL = applicationProperties.get(Constants.JIRAURL)
+ "/rest/agile/1.0/issue/" + key;
int issueId = getIssueId(auth, issueURL, key);
// Constants.REPORT.info(issueId);
return invokePostMethod(auth, sprintId, key, issueId);
// Constants.REPORT.info(statusCode);
}
private static int invokeGetMethod(String auth, String agileURL,
String sprint) {
int sprintId = 0;
int startAt = 0;
agileURL = agileURL + "?startAt=" + startAt;
sprintId = getSprintResult(agileURL, auth, sprint, startAt);
// sprintId = getSprintId(content, sprint, agileURL);
return sprintId;
}
private static int getSprintResult(String agileURL, String auth,
String sprint, int startAt) {
HttpGet post = new HttpGet(agileURL);
org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient();
post.setHeader("Content-type", "application/json");
post.setHeader("Authorization", "Basic " + auth);
HttpResponse response = null;
String content = null;
try {
response = httpClient.execute(post);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
content = CharStreams.toString(new InputStreamReader(response
.getEntity().getContent(), Charsets.UTF_8));
} catch (IllegalStateException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int SprintId = getSprintId(content, sprint, agileURL, startAt, auth);
if (SprintId != 0)
return SprintId;
return SprintId;
}
static int getSprintId(String content, String sprint, String agileURL,
int startAt, String auth) {
boolean flag = false;
int sprintId = 0;
Gson gson = new Gson(); // Class<String> data=new Class<String>();
Data values = gson.fromJson(content, Data.class);
for (Values data : values.getValues()) { // data.get
if (data.getName().equalsIgnoreCase(sprint))
// Constants.REPORT.info(sprintId=data.getId());
{
flag = true;
// Constants.REPORT.info(data);
// statusCode = response.getEntityInputStream().;
return sprintId = data.getId();
}
}
if (!flag) {
//Pagination
agileURL = agileURL.replaceAll(
"startAt=" + String.valueOf(startAt),
"startAt=" + String.valueOf(startAt += 50));
sprintId = getSprintResult(agileURL, auth, sprint, startAt);
if (sprintId != 0)
return sprintId;
}
return sprintId;
}
private static int getIssueId(String auth, String agileURL, String key) {
int issueId = 0;
try {
org.apache.http.impl.client.DefaultHttpClient httpClient = new org.apache.http.impl.client.DefaultHttpClient();
HttpGet post = new HttpGet(agileURL);
post.setHeader("Content-type", "application/json");
post.setHeader("Authorization", "Basic " + auth);
HttpResponse response = httpClient.execute(post);
String content = CharStreams.toString(new InputStreamReader(
response.getEntity().getContent(), Charsets.UTF_8));
Gson gson = new Gson(); // Class<String> data=new Class<String>();
IssueData issueValues = gson.fromJson(content, IssueData.class);
if (issueValues.getKey().equalsIgnoreCase(key))
issueId = issueValues.getId();
// Constants.REPORT.info(issueValues);
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
// vjErrorLog.info(Level.INFO, e);
}
return issueId;
}
private static int invokePostMethod(String auth, int sprintId, String key,
int issueId) {
int statusCode = 0;
try {
String postUrl = applicationProperties.get(Constants.JIRAURL)
+ "/rest/agile/1.0/sprint/" + sprintId + "/issue";
String str = "{\"issues\": [\"" + key + "\",\"" + issueId + "\"]}";
statusCode = invokePostMethod(auth, postUrl, str);
return statusCode;
} catch (Exception e) {
Constants.ERROR.info(Level.INFO, e);
// vjErrorLog.info(Level.INFO, e);
}
return statusCode;
}创建一个具有以下属性的IssueData类。并创建getter/setter还将overeride toString()方法。
private int id;
private String self;
private String key;https://stackoverflow.com/questions/37798456
复制相似问题