首先创建springboot工程,使用maven进行构建,pom依赖如下:
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter
org.springframework.boot
spring-boot-starter-test
test
com.atlassian.jira
jira-rest-java-client-core
5.1.6
io.atlassian.fugue
fugue
4.7.2
provided
加入依赖以后可以通过asynchronousJiraRestClientFactory进行登陆获取认证,本次使用用户名密码的方式进行校验,也可以使用其他 的方式进行校验(例如token的方式),登陆验证以后获取到jiraRestClient进行后续的操作。
public JiraRestClient loginJira(){
AsynchronousJiraRestClientFactory asynchronousJiraRestClientFactory = new AsynchronousJiraRestClientFactory();
JiraRestClient jiraRestClient = asynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(URI.create(jira地址), 用户名,密码);
return jiraRestClient;
}
通过查看接口可以看到可以获取到多种操作类型的client。
public interface JiraRestClient extends Closeable {
IssueRestClient getIssueClient();
SessionRestClient getSessionClient();
UserRestClient getUserClient();
GroupRestClient getGroupClient();
ProjectRestClient getProjectClient();
ComponentRestClient getComponentClient();
MetadataRestClient getMetadataClient();
SearchRestClient getSearchClient();
VersionRestClient getVersionRestClient();
ProjectRolesRestClient getProjectRolesRestClient();
AuditRestClient getAuditRestClient();
MyPermissionsRestClient getMyPermissionsRestClient();
void close() throws IOException;
}
简单示例获取对应的issue信息
Issue issue = jiraRestClient.getIssueClient().getIssue(此处是需要查询的issuekey).claim();
System.out.println(issue);
System.out.println(issue.getStatus()+"+++++++++++++++++");
System.out.println(issue.getStatus().getName()+"jira status ");
其他的操作都是获取对应的client进行操作即可,对应client可以进行的操作上边已经已经注释。