Thursday, March 8, 2018

Get the list of user installed plugin in JIRA

Goal:

To get the list of user installed plugin in a JIRA instance

Tools used:

Python with 'requests' module installed

Script:

import json
import requests
headers = {"Authorization": "Basic <CREDS base64 encoded>", "Content-Type": "application/json"}
url = "<base url>/rest/plugins/1.0/"
resp = requests.get(url, headers=headers)
ResponseJson = resp.content.decode("utf-8")
parsed_ResponseJson = json.loads(ResponseJson)
pluginsData = parsed_ResponseJson['plugins']

for plugin in pluginsData:
if plugin['userInstalled']:
print(plugin['name'], ",", plugin['version'], ",", plugin['vendor']['name'])

Tuesday, January 30, 2018

JIRA Rest API hints


To create a new jira project from template:


url="<baseurl>/rest/project-templates/1.0/createshared/<projectid>"
headers = {"Content-type": "application/json"}


data={}
data["key"]=projectkeyvalue
data["name"]=projectnamevalue
data["lead"]=projectleadusername

payload=json.dumps(data)
r=requests.post(url=url,data=payload,headers=headers)
print(r.status_code, r.reason)

print(r.text[:300] + '...')


Thursday, January 28, 2016

Groovy script to remove not active users from JIRA who has not logged into JIRA since 2016

import com.atlassian.jira.bc.security.login.LoginService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.user.util.UserUtil

def result = ""

UserManager userManager = ComponentAccessor.userManager
UserUtil userUtil = ComponentAccessor.userUtil
LoginService loginService = ComponentAccessor.getComponent(LoginService)

def myUser = ComponentAccessor.jiraAuthenticationContext?.getUser()

if (myUser) {
    userManager.getAllApplicationUsers().findAll{ user ->
        loginService.getLoginInfo(user.getName()).getLastLoginTime() != null
    }.each{ user ->
            def val = loginService.getLoginInfo(user.getName()).getLastLoginTime()
            def fulllogindate = new Date(val)
def year = fulllogindate[Calendar.YEAR]
        if (year < 2016) {
              if (userUtil.getNumberOfAssignedIssuesIgnoreSecurity(myUser,user)) {
              result += "User $user could not be removed because there are assigned issues!\r\n"
} else if (userUtil.getNumberOfReportedIssuesIgnoreSecurity(myUser,user)) {
            result += "User $user could not be removed because there are reported issues!\r\n"
        } else if (userUtil.getComponentsUserLeads(user)) {
           result += "User $user could not be removed because he leads a component!\r\n"
        } else {
            //userUtil.removeUser(myUser,user)
            result += "User $user removed.\r\n"
        }
} else {
result += "User $user used JIRA in 2016.\r\n"
}
}
}
result



I have commented the removeUser action.. You can do a dry run first and then choose to uncomment it and execure it

Thursday, November 26, 2015

JIRA Script to list all project names with the corresponding project administrator

Problem:

The JIRA users do not have visibility to all the projects available in the JIRA instance and they do not know who to contact in case they need access to a specific project.

Requirement:

Publish the JIRA project details with the Project admins list who can be contacted for access requests. It should be automated to be refreshed at least once a day.

Solution:

Below is the shell script to extract the JIRA Project name, KEY and the Project admin list and displays in a text file. The script can be scheduled to run through a Jenkins job and result can be published in Confluence.


curl -u username:password -X GET -H "Content-Type: application/json" http://URL/rest/api/2/project > projectList.json
ProjectsSize=`jq '.[] | length' projectList.json | wc -w`
ProjectAdminRoleId=10104 #Give the specific Role id for project admins in your organization. For the default "Administrator" role id will be 10002
echo -e "Project|KEY|ProjectAdmins" > List.txt
for (( i=0; i<$ProjectsSize; i++ ))
do
 tkey=`jq .[$i].key projectList.json`
 pkey=`echo $tkey | cut -d '"' -f 2`
 curl -u username:password -X GET -H "Content-Type: application/json" http://URL/rest/api/2/project/$pkey/role/$ProjectAdminRoleId > ProjectRole.json
 UserSize=`jq '.actors | length' ProjectRole.json`
 ProjectAdminList=
 for (( j=0; j<$UserSize; j++ ))
  do
   ProjectAdminList=$ProjectAdminList,`jq .actors[$j].name ProjectRole.json | cut -d '"' -f 2`
  done
  echo -e "`jq .[$i].name projectList.json | cut -d '"' -f 2`|`jq .[$i].key projectList.json | cut -d '"' -f 2`|`echo $ProjectAdminList | cut -c 2-`" >> List.txt
done


I have used shell scripting, curl+REST API for data extraction and jq for json parsing.  You can download jq from https://stedolan.github.io/jq/

Friday, November 20, 2015

About this blog...

Hi Reader

As a technical specialist of Software Tools and Processes, my work is to find and deploy right tools for the software projects and support them to achieve the Continuous Delivery flow.

As days go, i realized that i learn a lot of new things through the challenges i face every day and would definitely be helpful to the software developers and tools experts community out there.. So here i am.. Jotting down what i think will he helpful to people like me :)

Hope its helpful to the you who read this now!









And..... You are welcome ;)