-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjira_cli.sh
More file actions
80 lines (67 loc) · 2.35 KB
/
Copy pathjira_cli.sh
File metadata and controls
80 lines (67 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# Initialize variables to store the inputs
summary=""
description=""
monitoring=""
# Function to show script usage
usage() {
echo "Usage: $0 -s 'short summary/title' -d 'detailed problem description' -m 'Yes/No'"
echo "All inputs are required, summary can be max 45 characters long, -m can only be 'Yes' or 'No'"
exit 1
}
#if no input script will end and show usage - needed due to limited failed requests which can be made on JIRA API
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
# Use getopts to grab inputs from the command line
while getopts ":s:d:m:h" opt; do
case $opt in
s)
if [[ -z "$OPTARG" ]]; then
echo "Input for option -s cannot be blank" >&2
usage
elif [[ ${#OPTARG} -gt 45 ]]; then
echo "Input for option -s cannot be longer than 45 characters" >&2
usage
else
summary="$OPTARG"
fi
;;
d)
if [[ -z "$OPTARG" ]]; then
echo "Input for option -d cannot be blank" >&2
usage
else
description="$OPTARG"
fi
;;
m)
if [[ -z "$OPTARG" ]]; then
echo "Input for option -m cannot be blank" >&2
usage
elif [[ "$OPTARG" != "Yes" && "$OPTARG" != "No" && "$OPTARG" != "yes" && "$OPTARG" != "no" ]]; then
echo "Invalid input for option -m, allowed inputs are Yes/No" >&2
usage
else
monitoring="$OPTARG"
fi
;;
h) usage
;;
\?) echo "Invalid option -$OPTARG" >&2
usage
;;
esac
done
#define datetime so it will be automaticly passed to json
datetime=$(date +%F)T$(date +"%I:%M:%S")
# Show the inputs in the console
echo "summary: $summary"
echo "description: $description"
echo "monitoring: $monitoring"
echo "datetime: $datetime"
project=PROJECT_NAME
email=api@domain.com
api_key=$(cat /etc/adm/jira_api_key)
curl -i -u $email:$api_key -H 'Content-Type: application/json' -XPOST --data '{"fields":{"project":{"key":"PROJECT_NAME"},"summary":"'"$summary"'","assignee":"'"$assignee"'","customfield_10201":"'"$datetime"'","customfield_12100":{"value":"'"$monitoring"'"},"description":{"type":"doc","version":1,"content":[{"type":"paragraph","content":[{"type":"text","text":"'"$description"'"}]}]},"issuetype":{"name":"Outage"}}}' https://yourname.atlassian.net/rest/api/3/issue ; echo