Jira is one of the popular bug tracking tool developed by Atlassian. It also provides project management features inline with Agile methodology. Jira is basically written in Java & can integrate with source control programs like Perforce, Git, Clearcase, Subversion, TFS etc.
It also provides robust set of APIs which enables its integration with any system.
An interesting fact about its name 'JIRA': It is not an acronym, but a truncation of 'Gojira', the japanese name for 'Godzilla'. :)
Example to Create Issue & Search Issue:
This example shows how to consume Jira REST APIs from Java using REST Assured libraries.
NOTE: For the set up / usage of REST assured libraries can be found in another post.
https://advancedtestautomation.blogspot.in/2016/08/test-rest-web-services-using-rest.html
Step 2: Create a class file by name 'JiraConnect'.
Step 3: Define a main method with the below variables.
RestAssured.baseURI = "https://testserver.atlassian.net/rest/api/2";
String createIssueUrl = "/issue";
String searchurl = "/search?jql=assignee='testUser'&startAt=1&maxResults=1&fields=id,key,summary,description";
HashMap<String,String> headerMap = new HashMap<String,String>();
headerMap.put("Content-Type", "application/json");
headerMap.put("Authorization", "Basic bmC5jb20sdsdyYWtpbmczMjE=");
String createPaylod = "{\"fields\":{\"project\":{\"key\":\"CRE\"},\"summary\":\"Test REST API for creating an Issue\",\"description\":\"Creating an issue\",\"issuetype\":{\"name\":\"Bug\"},\"labels\":[\"Automation\"],\"assignee\":{\"name\":\"\"},\"environment\":\"TestEnv\",\"priority\":{\"name\":\"High\"}}}";
Step 4: Create a method 'createIssue' to create an issue / bug:
public static void createIssue(String url, HashMap<String,String> headerMap, String body){
Response response = null;
try{
response = RestAssured.given().log().all().headers(headerMap).body(body).post(url);
response.prettyPrint();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
Step 5: Create a method 'searchIssue' to search issues based on filter parameters like assignee, Results Limit, fields to be displayed in results.. etc.
public static void searchIssue(String url, HashMap<String,String> headerMap){
Response response = null;
try{
response = RestAssured.given().log().all().headers(headerMap).get(url);
response.prettyPrint();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
Step 6: Call the methods 'createIssue' and 'searchIssue' in main method accordingly.
Similar to the above, many such methods are available to perform actions on Jira thorough Jira REST APIs.
NOTE:
- Create Issue payload mentioned above can be modified according to needs.
{"fields": {"project": {"key": "CRE"},"summary": "Issue REST Summary","description": "Creating an issue","issuetype": {"name": "Bug"},"labels": ["Automation"],"assignee": {"name": ""},"environment": "TestEnv","priority": {"name": "Major"}}}
- Sample response for Create issue:
{
"id": "10002",
"key": "CRE-3",
"self": "https://testserver.atlassian.net/rest/api/2/issue/10002"
}
References:
https://developer.atlassian.com/jiradev/jira-apis
Superb.... Great. Very nice Information.
ReplyDeleteGlad, you found it useful.
DeleteHi, I am trying to connect with JIRA Rest Services with Postman first before I can automate them with rest assured. What Header should I use for Authentication key? How you have generated that key here?
ReplyDeleteHi, it is basically base64 encoded string using username & password used for accessting Jira.
DeleteHi , I am trying to get status of the issue but not able to get it via Rest Assured.But I was able to get the Jira Service desk issue status by using Jira Rest Client. Is there a way to get the status of the issue using Rest Assured ?
ReplyDeleteKr,
Yogesh
Hi Yogesh, Ideally you should have got the status with REST api also.
DeleteTry using the below endpoint, if that works:
https:///rest/api/2/issue/ISSUE-2?fields=status
Make sure to use APIToken instead of Password , as password support for API call is deprecated from jira side. I tried login to my jira cloud instance using postman (considering username & token & choosing Basic authorization authentication). It worked fine
DeleteThis is useful information for all of us building any software or website in Jira integration, but also check out free trial of workshop management software
ReplyDeleteAmazing article. Learn about okr framework here.
ReplyDeleteYour blog post on Jira is both informative and concise. I appreciate the detailed steps on creating issues and searching for them using REST APIs. It's a valuable resource for those looking to integrate Jira into their workflow. Keep up the great work!
ReplyDelete