Considering a scenario where there are multiple users who are inactive for the past two years, and now we wish to remove unwanted users who are inactive say 2 years back now so that we can perform these simple steps and get our work done very easily. Now to do so first, you might be aware of a few simple basics of Jenkins and Jira.
- Jira Instance
- Basic Understanding of Jira API
- Jenkins Pipeline
- Basic Understanding of bash
There are many cases where the users are no longer using Jira. Let us discuss one scenario here. While working with the enterprise version of Jira, one has to procure a license of Jira, and depending on the users the license cost is decided. There are many users who just log in to Jira to see the updates and then never return back. As soon as the user logs into Jira, the user profile is created and considered as a licensed user. In this case, unnecessarily the license gets wasted and the users really in need don’t get access to the tool. To eliminate the users who no longer use Jira we are making use of Jira API to remove the users from Jira DB.
Fetch Jira users
To fetch Jira users based on their last session, we can write a script in ScriptRunner, which is basically a plugin in Jira provided by Adaptavist. Make use of the groovy script to fetch the users based on their last login details. Store the output of the script in a CSV file so that we can pass it to the Jenkins pipeline to delete the user.
- Write a Jenkins script to delete unwanted users from Jira
- To do this we can make use of Jira API which is very helpful to interact with Jira. (Here we will use Jira Data Center (DC) rest API))
- Make sure you have global admin rights to the Jira instance to perform any operation.
- First of all, create a Jenkins pipeline in Jenkins and a Jenkins script in git/bitbucket or any VCS.
- Once done use appropriate credentials to authenticate git/bitbucket via Jenkins.
- While using Jira API in the script use appropriate credentials to interact with the Jira instance as well.
- To delete the users make use of the following Jira rest API
- DELETE /rest/api/2/user
- The query parameter used in this API is
- API Responses
- STATUS 400 Returned if the request is invalid or some other server error occurred.
- STATUS 401 Returned if the user is not authenticated.
- STATUS 204 Returned if the user was deleted successfully.
- STATUS 403 Returned if the caller does not have permission to remove the user.
- STATUS 404 Returned if the caller does have permission to remove the user but the user does not exist.
- Keeps Jira DB up to date
- Remove unnecessary users from Jira
- Useful in Jira enterprise edition
- Reduces user count
- Easy to implement
The above approach helps to remove/delete unwanted users from Jira and makes a robust Jira DB. Jira Rest APIs make work easy for organizations to deal with the Jira enterprise version.