Skip to content

Instantly share code, notes, and snippets.

@shurkin18
Last active November 10, 2023 03:54
Show Gist options
  • Save shurkin18/39413994033408bbf8b838457599de90 to your computer and use it in GitHub Desktop.
Save shurkin18/39413994033408bbf8b838457599de90 to your computer and use it in GitHub Desktop.
Search JIRA On-Prem for specific Issue and if none found - creates a new Issue via API
#!/bin/bash
# Please note: JIRA URL may be different for your setup, including all of the URL
# https://COMPANY-JIRA-URL.com/jira/rest/api/2/issue/ | you may need to play around with it to get it exact right
currentLoggedInUser=`stat -f '%u %Su' /dev/console | awk '{ print $2 }'`
echo "Currently logged in user is: $currentLoggedInUser"
#Create JIRA API ticket
curl \
-D- \
-u JIRA-API-USERNAME:JIRA-API-TOKEN \
-X POST \
-H "Content-Type: application/json" \
https://COMPANY-JIRA-URL.com/jira/rest/api/2/issue/ \
--data '
{
"fields":
{
"project":
{
"key": "IT"
},
"issuetype":
{
"id": "8"
},
"summary": "JIRA REST API TESTING - account: '$currentLoggedInUser'",
"description": "Creating an issue using project key and issue type ID using JIRA API. Ticket was created by running an API script.",
"reporter":
{
"name": "'$currentLoggedInUser'"
}
}
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment