forked from kubeflow/pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-build-image-status.sh
executable file
·85 lines (81 loc) · 2.5 KB
/
check-build-image-status.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
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -ex
# Usage: wait_for_builds "${BUILD_IDS[@]}"
# returns true if success, otherwise false.
function wait_for_builds {
local pending_ids=("$@") # copy pending build ids
local max_attempts=$(expr $TIMEOUT_SECONDS / 20)
for i in $(seq 1 ${max_attempts})
do
local new_pending_ids=()
for id in "${pending_ids[@]}"
do
status=$(gcloud builds describe $id --format='value(status)') || status="FETCH_ERROR"
case "$status" in
"SUCCESS")
echo "Build with id ${id} has succeeded."
;;
"WORKING" | "QUEUED")
new_pending_ids+=( "$id" )
;;
"FETCH_ERROR")
echo "Fetching cloud build status failed, retrying..."
new_pending_ids+=( "$id" )
;;
*)
echo "Fetching build log for build $id"
gcloud builds log "$id" || echo "Fetching build log failed"
# Intentionally placed this status echo at the end, because when a
# developer is looking at logs, sth at the end is most discoverable.
echo "Cloud build with build id ${id} failed with status ${status}"
return 1
;;
esac
done
pending_ids=("${new_pending_ids[@]}")
if [ 0 == "${#pending_ids[@]}" ]; then
echo "All cloud builds succeeded."
return 0
fi
echo "Cloud build in progress, waiting for 20 seconds..."
sleep 20
done
echo "Waiting for cloud build ids ${pending_ids[@]} timed out."
return 2
}
function wait_and_retry {
local max_attempts=3
local i
for i in $(seq 1 ${max_attempts})
do
if [ $i != 1 ]; then
echo "Retry #${i}, build images again..."
source "${DIR}/build-images.sh"
fi
if [ "$IMAGES_BUILDING" != true ]; then
echo "Images already built"
return 0
fi
if wait_for_builds "${BUILD_IDS[@]}"; then
echo "Images built successfully"
return 0
fi
done
echo "Images failed to build"
return 1
}
wait_and_retry