├── #createIssue.sh# ├── .gitignore ├── addAttachment.sh ├── addComment.sh ├── addUserToGroup ├── addWorklog.sh ├── createDashboard.sh ├── createFilter.sh ├── createIssue.sh ├── createProject.sh ├── deleteIssue.sh ├── deleteProject.sh ├── deleteWorklog.sh ├── editIssue.sh ├── getAllApplicationRoles.sh ├── getAllDashboards.sh ├── getAuditRecords.sh ├── getAvailableGadgets.sh ├── getField.sh ├── getFilter.sh ├── getIssueAttachments.sh ├── getIssueTypes.sh ├── getLicense.sh ├── getProjectList.sh ├── getWorkflow.sh ├── getWorklog.sh ├── parseJql.sh ├── readme.md ├── searchFilter.sh ├── updateAnnouncementBanner.sh └── updateFilter.sh /#createIssue.sh#: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issuetype_id="10001" 4 | project_id="10037" 5 | priority_id="2" 6 | description="This is a description of the issue" 7 | summary="Test issue created from a shell script" 8 | 9 | template='{ 10 | 11 | "fields": { 12 | "summary": "%s", 13 | "issuetype": { 14 | "id": "%s" 15 | }, 16 | "project": { 17 | "id": "%s" 18 | }, 19 | "priority": { 20 | "id": "%s" 21 | }, 22 | 23 | "description": { 24 | "type": "doc", 25 | "version": 1, 26 | "content": [ 27 | { 28 | "type": "paragraph", 29 | "content": [ 30 | { 31 | "text": "%s", 32 | "type": "text" 33 | } 34 | ] 35 | } 36 | ] 37 | } 38 | } 39 | }' 40 | 41 | json_final=$(printf "$template" \ 42 | "$summary" \ 43 | "$issuetype_id" \ 44 | "$project_id" \ 45 | "$priority_id" \ 46 | "$description") 47 | 48 | curl -i -X POST \ 49 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 50 | -H "Content-Type:application/json" \ 51 | -H "X-Atlassian-Token:no-check" \ 52 | "https://jiratutorial.atlassian.net/rest/api/3/issue/" \ 53 | -d \ 54 | "$json_final" 55 | 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ -------------------------------------------------------------------------------- /addAttachment.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issue_key="an-231" 4 | 5 | curl -s -i -X POST \ 6 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | -H "X-Atlassian-Token:no-check" \ 8 | -F "file=@/home/ravisagar/output.png" \ 9 | 'https://jiratutorial.atlassian.net/rest/api/3/issue/'$issue_key'/attachments' 10 | 11 | -------------------------------------------------------------------------------- /addComment.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issuekey="sd-28" 4 | 5 | curl -i -X POST \ 6 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | -H "Content-Type:application/json" \ 8 | -H "X-Atlassian-Token:no-check" \ 9 | "https://jiratutorial.atlassian.net/rest/api/3/issue/$issuekey/comment" \ 10 | -d \ 11 | '{ 12 | "body": { 13 | "type": "doc", 14 | "version": 1, 15 | "content": [ 16 | { 17 | "type": "paragraph", 18 | "content": [ 19 | { 20 | "text": "I am working on the issue", 21 | "type": "text" 22 | } 23 | ] 24 | } 25 | ] 26 | } 27 | }' 28 | -------------------------------------------------------------------------------- /addUserToGroup: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | group="jira-developers" 4 | accountid="557058:f2a3043a-ebcb-4815-9277-e0e14c4d9776" 5 | 6 | template='{ 7 | "accountId": "%s" 8 | }' 9 | 10 | json_final=$(printf "$template" "$accountid") 11 | curl -i -X POST \ 12 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 13 | -H "Content-Type:application/json" \ 14 | -H "X-Atlassian-Token:no-check" \ 15 | "https://jiratutorial.atlassian.net/rest/api/3/group/user?groupname=jira-developers" \ 16 | -d \ 17 | "$json_final" 18 | 19 | -------------------------------------------------------------------------------- /addWorklog.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | 4 | # Make sure there is a ~/jiraissues.csv file in your home directory 5 | # Format of the file should be like this 6 | # KEY-1,2h,02/06/2021 7 | # Just run the script 8 | 9 | while read line 10 | do 11 | issuekey="$(echo $line | cut -d ',' -f 1)" 12 | worklog="$(echo $line | cut -d ',' -f 2)" 13 | d="$(echo $line | cut -d ',' -f 3)" 14 | 15 | day=$(echo $d | cut -d '/' -f 1) 16 | month=$(echo $d | cut -d '/' -f 2) 17 | year=$(echo $d | cut -d '/' -f 3) 18 | 19 | curl -i -X POST \ 20 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 21 | -H "Content-Type:application/json" \ 22 | -H "X-Atlassian-Token:no-check" \ 23 | "https://jiratutorial.atlassian.net/rest/api/3/issue/$issuekey/worklog" \ 24 | -d \ 25 | '{ 26 | "timeSpent": "'$worklog'", 27 | "started": "'$year'-'$month'-0'$day'T18:00:00.751+0000" 28 | }' 29 | 30 | sleep .5 31 | done < ~/jiraissues.csv 32 | 33 | notify-send "Timesheets" "All done!" 34 | 35 | exit 36 | -------------------------------------------------------------------------------- /createDashboard.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Usage 4 | # ./createDashboard.sh "Dashboard Description" "Dashboard Name" 5 | 6 | DASHBOARD_DESCRIPTION=$1 7 | DASHBOARD_NAME=$2 8 | 9 | JSON_TEMPLATE='{ 10 | "description": "%s", 11 | "editPermissions": [], 12 | "name": "%s", 13 | "sharePermissions": [] 14 | }' 15 | 16 | JSON_FINAL=$(printf "$JSON_TEMPLATE" \ 17 | "$DASHBOARD_DESCRIPTION" \ 18 | "$DASHBOARD_NAME") 19 | 20 | curl -i -X POST \ 21 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 22 | -H "Content-Type:application/json" \ 23 | -H "X-Atlassian-Token:no-check" \ 24 | "https://jiratutorial.atlassian.net/rest/api/3/dashboard" \ 25 | -d \ 26 | "$JSON_FINAL" 27 | -------------------------------------------------------------------------------- /createFilter.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Usage 4 | # ./createFilter.sh "priority = High" "Filter High Priority" "Description of the Filter" 5 | 6 | FILTER_JQL=$1 7 | FILTER_NAME=$2 8 | FILTER_DESCRIPTION=$3 9 | 10 | JSON_TEMPLATE='{ 11 | "description": "%s", 12 | "jql": "%s", 13 | "name": "%s" 14 | }' 15 | 16 | JSON_FINAL=$(printf "$JSON_TEMPLATE" \ 17 | "$FILTER_DESCRIPTION" \ 18 | "$FILTER_JQL" \ 19 | "$FILTER_NAME") 20 | 21 | curl -i -X POST \ 22 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 23 | -H "Content-Type:application/json" \ 24 | -H "X-Atlassian-Token:no-check" \ 25 | "https://jiratutorial.atlassian.net/rest/api/3/filter" \ 26 | -d \ 27 | "$JSON_FINAL" 28 | -------------------------------------------------------------------------------- /createIssue.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issuetype_id="10001" 4 | project_id="10037" 5 | priority_id="2" 6 | description="This is a desction of the issue" 7 | summary="Test issue created from a shell script" 8 | 9 | template='{ 10 | 11 | "fields": { 12 | "summary": "%s", 13 | "issuetype": { 14 | "id": "%s" 15 | }, 16 | "project": { 17 | "id": "%s" 18 | }, 19 | "priority": { 20 | "id": "%s" 21 | }, 22 | 23 | "description": { 24 | "type": "doc", 25 | "version": 1, 26 | "content": [ 27 | { 28 | "type": "paragraph", 29 | "content": [ 30 | { 31 | "text": "%s", 32 | "type": "text" 33 | } 34 | ] 35 | } 36 | ] 37 | } 38 | } 39 | }' 40 | 41 | json_final=$(printf "$template" \ 42 | "$summary" \ 43 | "$issuetype_id" \ 44 | "$project_id" \ 45 | "$priority_id" \ 46 | "$description") 47 | 48 | curl -i -X POST \ 49 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 50 | -H "Content-Type:application/json" \ 51 | -H "X-Atlassian-Token:no-check" \ 52 | "https://jiratutorial.atlassian.net/rest/api/3/issue/" \ 53 | -d \ 54 | "$json_final" 55 | 56 | -------------------------------------------------------------------------------- /createProject.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | key="NEWPRJKEY" 4 | project_name="New New Project" 5 | project_type_key="business" 6 | project_template_key="com.atlassian.jira-core-project-templates:jira-core-project-management" 7 | project_description="This project will be used to do magic" 8 | lead_account_id="557058:f2a3043a-ebcb-4815-9277-e0e14c4d9776" 9 | url="https://www.ravisagar.com" 10 | assignee_type="PROJECT_LEAD" 11 | avatar_id=10200 12 | notification_scheme=10007 13 | 14 | template=' 15 | { 16 | "key": "%s", 17 | "name": "%s", 18 | "projectTypeKey": "%s", 19 | "projectTemplateKey": "%s", 20 | "description": "%s", 21 | "leadAccountId": "%s", 22 | "url": "%s", 23 | "assigneeType": "%s", 24 | "avatarId": %s, 25 | "notificationScheme": %s 26 | } 27 | ' 28 | 29 | 30 | json_final=$(printf "$template" \ 31 | "$key" \ 32 | "$project_name" \ 33 | "$project_type_key" \ 34 | "$project_template_key" \ 35 | "$project_description" \ 36 | "$lead_account_id" \ 37 | "$url" \ 38 | "$assignee_type" \ 39 | "$avatar_id" \ 40 | "$notification_scheme") 41 | 42 | curl -i -X POST \ 43 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 44 | -H "Content-Type:application/json" \ 45 | -H "X-Atlassian-Token:no-check" \ 46 | "https://jiratutorial.atlassian.net/rest/api/3/project/" \ 47 | -d \ 48 | "$json_final" 49 | -------------------------------------------------------------------------------- /deleteIssue.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issue_key="an-216" 4 | 5 | curl -s -X \ 6 | DELETE -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | "https://jiratutorial.atlassian.net/rest/api/3/issue/$issue_key?deleteSubtasks=true" \ 8 | | jq 9 | -------------------------------------------------------------------------------- /deleteProject.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | project_key=$1 4 | 5 | curl -s -X \ 6 | DELETE -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | "https://jiratutorial.atlassian.net/rest/api/3/project/$project_key" \ 8 | | jq 9 | -------------------------------------------------------------------------------- /deleteWorklog.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | ISSUE=$1 4 | WORKLOGID=$2 5 | 6 | curl -s -X \ 7 | DELETE -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 8 | "https://jiratutorial.atlassian.net/rest/api/latest/issue/$ISSUE/worklog/$WORKLOGID" 9 | -------------------------------------------------------------------------------- /editIssue.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | issue_key="an-233" 4 | priority_id="3" 5 | description="Upated: This is a description of the issue" 6 | summary="Test issue updated from a shell script" 7 | number_field=9999 8 | text_field="Update: This is a text field" 9 | template='{ 10 | 11 | "fields": { 12 | "summary": "%s", 13 | "priority": { 14 | "id": "%s" 15 | }, 16 | "customfield_10152":%s, 17 | "customfield_10114":"%s", 18 | "description": { 19 | "type": "doc", 20 | "version": 1, 21 | "content": [ 22 | { 23 | "type": "paragraph", 24 | "content": [ 25 | { 26 | "text": "%s", 27 | "type": "text" 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | } 34 | }' 35 | 36 | json_final=$(printf "$template" \ 37 | "$summary" \ 38 | "$priority_id" \ 39 | "$number_field" \ 40 | "$text_field" \ 41 | "$description") 42 | 43 | curl -i -X PUT \ 44 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 45 | -H "Content-Type:application/json" \ 46 | -H "X-Atlassian-Token:no-check" \ 47 | "https://jiratutorial.atlassian.net/rest/api/3/issue/$issue_key" \ 48 | -d \ 49 | "$json_final" 50 | 51 | -------------------------------------------------------------------------------- /getAllApplicationRoles.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/applicationrole" \ 6 | | jq '.[] | "\(.key)" ' 7 | -------------------------------------------------------------------------------- /getAllDashboards.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/dashboard" \ 6 | | jq '.dashboards[] | "\(.owner.accountId),\(.name),\(.view)"' 7 | -------------------------------------------------------------------------------- /getAuditRecords.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/auditing/record" \ 6 | | jq '.records[] | "\(.created),\(.authorKey),\(.category),\(.summary),\(.objectItem.name)"' 7 | -------------------------------------------------------------------------------- /getAvailableGadgets.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/dashboard/gadgets" \ 6 | | jq '.gadgets[] | "\(.uri),\(.title),\(.moduleKey)"' 7 | -------------------------------------------------------------------------------- /getField.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "id,key,name,schema.custom" 4 | curl -s \ 5 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 6 | "https://jiratutorial.atlassian.net/rest/api/3/field" \ 7 | | jq -r '.[] | "\(.id),\(.key),\(.name),\(.schema.custom)"' 8 | -------------------------------------------------------------------------------- /getFilter.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | FILTER_ID=$1 4 | 5 | curl -s \ 6 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | "https://jiratutorial.atlassian.net/rest/api/3/filter/$FILTER_ID" \ 8 | | jq -r '.jql' 9 | -------------------------------------------------------------------------------- /getIssueAttachments.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" 'https://jiratutorial.atlassian.net/rest/api/3/issue/IOSTWO-21' | jq '.fields.attachment[] | .content' 4 | -------------------------------------------------------------------------------- /getIssueTypes.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | echo "id,name,subtask,scope" 4 | curl -s \ 5 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 6 | "https://jiratutorial.atlassian.net/rest/api/3/issuetype" \ 7 | | jq -r '.[] | "\(.id),\(.name),\(.subtask),\(.scope.type)"' 8 | -------------------------------------------------------------------------------- /getLicense.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/instance/license" \ 6 | -------------------------------------------------------------------------------- /getProjectList.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | echo "id,key,name,lead-displayName" 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/project/search?expand=lead" \ 6 | | jq -r '.values[] | "\(.id),\(.key),\(.name),\(.lead.displayName)"' 7 | -------------------------------------------------------------------------------- /getWorkflow.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/workflow/search" \ 6 | -------------------------------------------------------------------------------- /getWorklog.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | ISSUE=$1 4 | 5 | curl -s \ 6 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | "https://jiratutorial.atlassian.net/rest/api/latest/issue/$ISSUE/worklog" \ 8 | | jq -r '.worklogs[] | "\(.id),\(.created),\(.timeSpent)"' 9 | -------------------------------------------------------------------------------- /parseJql.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | jql="filter=10103" 4 | > /tmp/tmp.csv 5 | curl -s \ 6 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 7 | "https://jiratutorial.atlassian.net/rest/api/3/search?jql=$jql" \ 8 | | jq -r '.issues[] | "\(.key),\(.fields.summary) "' >> /tmp/tmp.csv 9 | 10 | while read line 11 | do 12 | notify-send "$(echo $line | cut -d ',' -f 1)" \ 13 | "$(echo $line | cut -d ',' -f 2)" 14 | sleep .5 15 | done < /tmp/tmp.csv 16 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | These are collection of scripts to help you interact with Jira. 2 | 3 | # Objective 4 | * Learn how to interact with Jira using REST API. 5 | * Solve your day to day problems. 6 | * Have lot of fun. 7 | 8 | # How to use the scripts? 9 | * Set an environment variable called JIRATUTORIAL_AUTH which is used in the scripts. You can use ~/.bashrc or ~/.xinitrc file or any other way you are familiar with to do this. In this [video](https://www.ravisagar.in/videos/jira-rest-api-generate-api-token-and-base64-encoding) I have explained how to generate the token and base64 encode it. 10 | 11 | # Dependencies 12 | * jq: Used to parse the JSON. 13 | * cut: Used to cut string based on delimiter. 14 | 15 | # Useful links 16 | * [Ravi Sagar YouTube Channel](https://youtube.com/ravisagar1): You will find videos to learn Jira. 17 | * [Mastering Jira REST API Videos](https://www.ravisagar.in/courses/mastering-jira-rest-api): Videos related to only Jira REST API. 18 | 19 | -------------------------------------------------------------------------------- /searchFilter.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | curl -s \ 4 | GET -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 5 | "https://jiratutorial.atlassian.net/rest/api/3/filter/search" \ 6 | | jq -r '.values | .[] | "\(.id),\(.name)"' 7 | 8 | -------------------------------------------------------------------------------- /updateAnnouncementBanner.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | json='{ 4 | "visibility": "private", 5 | "isEnabled": true, 6 | "isDismissible": false, 7 | "message": "For support raise ticket here: https://www.ravisagar.in/support" 8 | }' 9 | 10 | curl -i -X PUT \ 11 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 12 | -H "Content-Type:application/json" \ 13 | -H "X-Atlassian-Token:no-check" \ 14 | "https://jiratutorial.atlassian.net/rest/api/3/announcementBanner" \ 15 | -d \ 16 | "$json" 17 | -------------------------------------------------------------------------------- /updateFilter.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Usage 4 | # ./updateFilter.sh "10132" "priority = High" "Filter High Priority" "Description of the Filter" 5 | 6 | 7 | FILTER_ID=$1 8 | FILTER_JQL=$2 9 | FILTER_NAME=$3 10 | FILTER_DESCRIPTION=$4 11 | 12 | JSON_TEMPLATE='{ 13 | "description": "%s", 14 | "jql": "%s", 15 | "name": "%s" 16 | }' 17 | 18 | JSON_FINAL=$(printf "$JSON_TEMPLATE" \ 19 | "$FILTER_DESCRIPTION" \ 20 | "$FILTER_JQL" \ 21 | "$FILTER_NAME") 22 | 23 | curl -i -X PUT \ 24 | -H "Authorization:Basic $JIRATUTORIAL_AUTH" \ 25 | -H "Content-Type:application/json" \ 26 | -H "X-Atlassian-Token:no-check" \ 27 | "https://jiratutorial.atlassian.net/rest/api/3/filter/$FILTER_ID" \ 28 | -d \ 29 | "$JSON_FINAL" 30 | --------------------------------------------------------------------------------