File tree Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Expand file tree Collapse file tree 3 files changed +34
-8
lines changed Original file line number Diff line number Diff line change @@ -89,9 +89,9 @@ module "build" {
89
89
timeout = each. value . timeout
90
90
}
91
91
92
- resource "null_resource" "run_build" {
93
- count = length (local. updated_builds ) > 0 ? 1 : 0
92
+ resource "terraform_data" "run_build" {
94
93
depends_on = [module . build ]
94
+
95
95
provisioner "local-exec" {
96
96
interpreter = [" /bin/bash" , " -c" ]
97
97
command = " ${ path . module } /scripts/build-run.sh"
Original file line number Diff line number Diff line change 1
1
#! /bin/bash
2
2
set -e
3
3
4
+ # max wait time = 60 × 10s = 10 minutes
5
+ MAX_RETRIES=60
6
+ RETRY_INTERVAL=10 # seconds
7
+
4
8
if [[ -z " ${IBMCLOUD_API_KEY} " ]]; then
5
9
echo " IBMCLOUD_API_KEY is required" >&2
6
10
exit 1
@@ -32,7 +36,33 @@ ibmcloud login -r "${REGION}" -g "${RESOURCE_GROUP_ID}" --quiet
32
36
ibmcloud ce project select -n " ${CE_PROJECT_NAME} "
33
37
34
38
# run a build for all builds
39
+ # we check for status build to be succeeded before we finish with script.
40
+ # This is needed in a case we deploy app, which needs build_run to be finished.
35
41
for build in $BUILDS ; do
36
- echo " $build "
37
- ibmcloud ce buildrun submit --build " $build "
42
+ echo " Submitting build: $build "
43
+ run_build_name=$( ibmcloud ce buildrun submit --build " $build " --output json | jq -r ' .name' )
44
+
45
+ echo " Waiting for build run $run_build_name to complete..."
46
+ retries=0
47
+ while true ; do
48
+ status=$( ibmcloud ce buildrun get --name " $run_build_name " --output json | jq -r ' .status' )
49
+ echo " Status: $status "
50
+ if [[ " $status " == " succeeded" ]]; then
51
+ echo " Build $build succeeded"
52
+ break
53
+
54
+ elif [[ " $status " == " Failed" || " $status " == " Error" ]]; then
55
+ echo " Build $build failed"
56
+ exit 1
57
+ fi
58
+
59
+ # if max time timeout then finish with error
60
+ if [[ $retries -ge $MAX_RETRIES ]]; then
61
+ echo " Build $build did not complete after $MAX_RETRIES retries. Timing out."
62
+ exit 1
63
+ fi
64
+
65
+ retries=$(( retries + 1 ))
66
+ sleep " $RETRY_INTERVAL "
67
+ done
38
68
done
Original file line number Diff line number Diff line change @@ -10,9 +10,5 @@ terraform {
10
10
source = " hashicorp/external"
11
11
version = " 2.3.5"
12
12
}
13
- null = {
14
- source = " hashicorp/null"
15
- version = " 3.2.4"
16
- }
17
13
}
18
14
}
You can’t perform that action at this time.
0 commit comments