首先創建springboot工程,使用maven進行構建,pom依賴如下:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
<!-- 使用jira-rest-cilent的依賴--> <dependency> <groupId>com.atlassian.jira</groupId> <artifactId>jira-rest-java-client-core</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>io.atlassian.fugue</groupId> <artifactId>fugue</artifactId> <version>4.7.2</version> <scope>provided</scope> </dependency> </dependencies>
加入依賴以后可以通過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(); //可以進行issue相關的操作 SessionRestClient getSessionClient(); UserRestClient getUserClient(); //jira用戶相關的操作 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可以進行的操作上邊已經已經注釋。