-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyaku_run.sh
executable file
·115 lines (95 loc) · 3.79 KB
/
yaku_run.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
## *************************************
## UNCOMMENT for creating a new config
## *************************************
# ## Create config object:
# config_json_response=$(curl -sX 'POST' \
# "${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/configs" \
# -H 'accept: application/json' \
# -H "Authorization: Bearer ${YAKU_API_TOKEN}" \
# -H 'Content-Type: application/json' \
# -d '{
# "name": "Yaku jenkins Config",
# "description": "Config to run in Jenkins job"
# }')
# echo $config_json_response
# CONFIG_ID=$(echo $config_json_response | grep -o '"id":[0-9]*' | sed 's/"id"://')
# echo $CONFIG_ID
## *************************************
## UNCOMMENT for creating a new release
## *************************************
# ## Create release
# release_json_response=$(curl -sX'POST' \
# "${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/releases" \
# -H 'accept: application/json' \
# -H "Authorization: Bearer ${YAKU_API_TOKEN}" \
# -H 'Content-Type: application/json' \
# -d "{
# \"name\": \"Release 24-Q4\",
# \"approvalMode\": \"one\",
# \"qgConfigId\": ${CONFIG_ID},
# \"plannedDate\": \"2024-12-25T13:32:07.749Z\"}")
# RELEASE_ID=$(echo $release_json_response | grep -o '"id":[0-9]*' | sed 's/"id"://')
# echo $RELEASE_ID
## *********************************************
## UNCOMMENT for uploading files to yaku config
## *********************************************
## Upload config files:
## response code should be 201
# curl -sX'POST' \
# "${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/configs/${CONFIG_ID}/files" \
# -H 'accept: */*' \
# -H "Authorization: Bearer ${YAKU_API_TOKEN}" \
# -H 'Content-Type: multipart/form-data' \
# -F '[email protected];type=application/x-yaml' \
# -F 'filename=qg-config.yaml'
# curl -sX'POST' \
# "${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/configs/${CONFIG_ID}/files" \
# -H 'accept: */*' \
# -H "Authorization: Bearer ${YAKU_API_TOKEN}" \
# -H 'Content-Type: multipart/form-data' \
# -F 'content=@test_single.yaml;type=application/x-yaml' \
# -F 'filename=test-single.yaml'
# curl -sX'POST' \
# "${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/configs/${CONFIG_ID}/files" \
# -H 'accept: */*' \
# -H "Authorization: Bearer ${YAKU_API_TOKEN}" \
# -H 'Content-Type: multipart/form-data' \
# -F 'content=@test_single_data.json;type=application/json' \
# -F 'filename=test_single_data.json'
## start yaku run
run_json_response=$(curl -sX'POST' \
"${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/runs" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${YAKU_API_TOKEN}" \
-H 'Content-Type: application/json' \
-d "{\"configId\": ${CONFIG_ID}}")
RUN_ID=$(echo $run_json_response | grep -o '"id":[0-9]*' | sed 's/"id"://')
## get run status
status=""
max_attempts=10
attempt=0
# Loop until the status is "finished"
while [ "$status" != '"completed"' ] && [ $attempt -lt $max_attempts ]; do
((attempt++))
run_status_json=$(curl -sX'GET' \
"${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/runs/${RUN_ID}" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${YAKU_API_TOKEN}")
status=$(echo "$run_status_json" | grep -o '"status"[[:space:]]*:[[:space:]]*"[a-zA-Z]*"' | sed 's/"status"://')
echo "Run status: $status"
sleep 5
done
if [[ "$status" == '"completed"' ]]; then
echo "Run was completed"
else
echo "Max attempts reached. Run didn't complete'"
fi
## Get release status
release_status_json=$(curl -sX'GET' \
"${YAKU_ENV_URL}/namespaces/${NAMESPACE_ID}/releases/${RELEASE_ID}" \
-H 'accept: application/json' \
-H "Authorization: Bearer ${YAKU_API_TOKEN}")
release_status=$(echo "$release_status_json" | grep -o '"approvalState"[[:space:]]*:[[:space:]]*"[a-zA-Z]*"' | sed 's/"approvalState"://')
echo "Release status: $release_status"
echo $release_status > .release_status