-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_jira.sh
executable file
·55 lines (48 loc) · 1.51 KB
/
update_jira.sh
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
#!/bin/sh
###########
# This script was originally intended to be used as a post-build action for a jenkins
# build job. It pulls the changelog from the jenkins job and updates each Jira ticket
# found with the current build number.
#
## IMPORTANT:
# This script is also dependent on the get_jiras.py script that pulls
#
## ASSUMPTIONS:
# You are using both Jira and Jenkins
# You have set the following environment variables:
# JIRA_USERNAME
# JIRA_PASSWORD
# BUILD_NUMBER
#
#
## USAGE INSTRUCTIONS:
# Run this script as a post-build step. The get_jiras.py script needs to be in the same
# directory as this script.
# ./update_jira.sh
###########
JIRA_URL="https://jira.yourcompanydomain.com"
BUILD_URL="https://buildmachine.yourcompanydomain.net/view/project_folder/job/project_name/${BUILD_NUMBER}/api/json"
if [ -z "${JIRA_USERNAME}" ]; then
echo "JIRA_USERNAME environment variable is unset or empty, skipping update JIRA process."
exit 0
fi
set -x # echo on
# retrieve build_json.txt
curl \
-sS \
-o build_json.txt \
-u ${JIRA_USERNAME}:${JIRA_PASSWORD} \
${BUILD_URL}
# parse build_json.txt
JIRAS=`get_jiras.py`
for jira in $JIRAS; do
echo "Setting JIRA ${jira} build fixed to ${BUILD_NUMBER}"
curl \
--silent \
-D- \
-u ${JIRA_USERNAME}:${JIRA_PASSWORD} \
-X PUT \
--data "{ \"fields\": { \"customfield_10094\":\"${BUILD_NUMBER}\" } }" \
-H "Content-Type: application/json" \
${JIRA_URL}/rest/api/2/issue/${jira}
done