-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoll.sh
73 lines (51 loc) · 1.92 KB
/
poll.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Poll for new build requests, and kick off the builds
# Author: Doug Bass
# Copyright 2019 ConnectALL LLC
. setup.sh
if [ ! -f lasttime ]; then
touch lasttime
fi
# Get the last time a poll was run and build the json request
lastRun="`date -r lasttime "+%Y-%m-%d %H:%M:%S"`.001"
echo Last run was $lastRun
json="
{\"appLinkName\":\"JiraRequestBuild2Jenkins\",
\"origin\":\"source\",
\"lastModifiedTime\":\"$lastRun\"
}"
#Date must be in this format: 2017-08-24 14:30:00.000
echo "Send JSON: $json"
echo "via ${ConnectAllUrl}/api/2/postRecord?apikey=$ConnectAllApiKey"
# Poll for any new build requests
curl \
--header "Content-Type: application/json;charset=UTF-8" -X POST \
-d "$json" \
${ConnectAllUrl}/connectall/api/2/search?apikey=$ConnectAllApiKey | tee request.json
touch lasttime
echo
# Parse out the build to run - currently it only finds one build to Run
# @todo for loop to parse out all the build requests
totalrecords=`jq <request.json .totalrecords`
i=0
while [ $i -lt $totalrecords ]
do
#workspace=`cat request.json | sed -e 's/[{}]/''/g' | awk -v RS=',"' -F: '/workspace/ {print $2}' | sed -e 's/\"//g'`
workspace=`jq <request.json .data[$i].fields.workspace | sed -e 's/\"//g'`
echo
echo Workspace is $workspace
#artifact_id=`cat request.json | sed -e 's/[{}]/''/g' | awk -v RS='[[]"' -F: '/id/ {print $2}' | sed -e 's/\"//g' | sed -e 's/,fields//g'`
artifact_id=`jq <request.json .data[$i].id | sed -e 's/\"//g'`
issuetype=`jq <request.json .data[$i].issuetype | sed -e 's/\"//g'`
title=`jq <request.json .data[$i].title | sed -e 's/\"//g'`
echo
echo id is $artifact_id
# Send the build request to jenkins
if [ "$workspace" = "" ]; then
echo "Nothing to build"
else
wget --auth-no-challenge --http-user=dbass --http-password=g2gp4wd --secure-protocol=TLSv1 \
${JenkinsUrl}/job/${workspace}/buildWithParameters?token=$JenkinsApiKey\&artifact_id=$artifact_id
fi
i=$(( $i + 1 ))
echo processed record number $i
done