Skip to content

Commit 446f514

Browse files
Moved triggering pipelines to separate script
1 parent be529bf commit 446f514

2 files changed

Lines changed: 54 additions & 41 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -258,47 +258,7 @@ jobs:
258258
- run:
259259
name: Trigger pipelines
260260
command: |
261-
for PIPELINE in << parameters.pipelines_to_trigger >> ; do
262-
echo "Triggering pipeline with source $PIPELINE"
263-
EVENT_ID=`curl -s -X POST -H "content-type: application/json" -d "{ }" http://spinnaker/api/v1/webhooks/webhook/$PIPELINE | jq -r .eventId`
264-
echo "eventId: $EVENT_ID"
265-
sleep 5 # Let pipeline start
266-
PASS=`cat ~/.hal/default/profiles/gate-local.yml | grep password`
267-
PASS=${PASS#*:\ }
268-
USER=`cat ~/.hal/default/profiles/gate-local.yml | grep name`
269-
USER=${USER#*:\ }
270-
ALL_APPS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications" | jq -r .[].name`
271-
MAX_ATTEMPTS=20
272-
for APP in $ALL_APPS ; do
273-
PIPELINE_NAME=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].name`
274-
ATTEMPTS=0
275-
while [[ $PIPELINE_NAME != "" ]] && [ $ATTEMPTS -lt $MAX_ATTEMPTS ] ; do
276-
echo "Checking pipeline $PIPELINE_NAME status"
277-
STATUS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].status`
278-
if [ -n $STATUS ] && [[ $STATUS == "NOT_STARTED" ]] ; then
279-
echo "Waiting for pipeline $PIPELINE_NAME to start"
280-
sleep 3
281-
elif [ -n $STATUS ] && [[ $STATUS == "RUNNING" ]] ; then
282-
echo "Waiting for pipeline $PIPELINE_NAME to finish"
283-
sleep 3
284-
elif [ -n $STATUS ] && [[ $STATUS != "SUCCEEDED" ]] ; then
285-
echo "Pipeline $PIPELINE_NAME exited with status $STATUS"
286-
exit 1
287-
elif [ -n $STATUS ] && [[ $STATUS == "SUCCEEDED" ]] ; then
288-
echo "$Pipeline PIPELINE_NAME succeded"
289-
break
290-
else
291-
echo "Status of pipeline is: $STATUS"
292-
exit 1
293-
fi
294-
((++ATTEMPTS))
295-
done
296-
if [ $ATTEMPTS -ge $MAX_ATTEMPTS ] ; then
297-
echo "Check timed out"
298-
exit 1
299-
fi
300-
done
301-
done
261+
.circleci/libs/trigger-pipelines.sh << parameters.pipelines_to_trigger >>
302262
303263
workflows:
304264
periodic:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash -e
2+
for PIPELINE in $@ ; do
3+
4+
PASS=`cat ~/.hal/default/profiles/gate-local.yml | grep password`
5+
PASS=${PASS#*:\ }
6+
USER=`cat ~/.hal/default/profiles/gate-local.yml | grep name`
7+
USER=${USER#*:\ }
8+
ALL_APPS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications" | jq -r .[].name`
9+
MAX_ATTEMPTS=20
10+
11+
echo "Triggering pipeline with source $PIPELINE"
12+
EVENT_ID=`curl -s -X POST -H "content-type: application/json" -d "{ }" http://spinnaker/api/v1/webhooks/webhook/$PIPELINE | jq -r .eventId`
13+
echo "eventId: $EVENT_ID"
14+
15+
for APP in $ALL_APPS ; do
16+
PIPELINE_NAME=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].name`
17+
ATTEMPTS=0
18+
19+
while [[ $PIPELINE_NAME != "" ]] && [ $ATTEMPTS -lt $MAX_ATTEMPTS ] ; do
20+
echo "Checking pipeline $PIPELINE_NAME status"
21+
STATUS=`curl -s -X GET --user "$USER:$PASS" "http://spinnaker/api/v1/applications/$APP/executions/search?triggerTypes=webhook&eventId=$EVENT_ID" | jq -r .[].status`
22+
23+
case $STATUS in
24+
25+
"NOT_STARTED")
26+
echo "Waiting for pipeline $PIPELINE_NAME to start"
27+
sleep 3
28+
;;
29+
30+
"RUNNING")
31+
echo "Waiting for pipeline $PIPELINE_NAME to finish"
32+
sleep 3
33+
;;
34+
35+
"SUCCEEDED")
36+
echo "$Pipeline PIPELINE_NAME succeded"
37+
break
38+
;;
39+
40+
*)
41+
echo "Pipeline $PIPELINE_NAME exited with status $STATUS"
42+
exit 1
43+
;;
44+
esac
45+
((++ATTEMPTS))
46+
done
47+
48+
if [ $ATTEMPTS -ge $MAX_ATTEMPTS ] ; then
49+
echo "Check timed out"
50+
exit 1
51+
fi
52+
done
53+
done

0 commit comments

Comments
 (0)