-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·66 lines (57 loc) · 2.5 KB
/
entrypoint.sh
File metadata and controls
executable file
·66 lines (57 loc) · 2.5 KB
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
#!/bin/bash -l
execution_id=${1}
client_id=${2}
client_secret=${3}
realm=${4}
debug=${5}
repo_url=${6}
idm_base_url=${7}
workflow_api_base_url=${8}
origin_branch=${9}
feature_branch=${10}
extra_inputs=${11}
export client_id=$client_id
export client_secret=$client_secret
secret_stk_login=$(curl -s --location --request POST "$idm_base_url/realms/$realm/protocol/openid-connect/token" \
--header "Content-Type: application/x-www-form-urlencoded" \
--data-urlencode "client_id=$client_id" \
--data-urlencode "grant_type=client_credentials" \
--data-urlencode "client_secret=$client_secret" | jq -r .access_token)
put_workflow_url="$workflow_api_base_url/workflows/$execution_id"
decoded_extra_inputs=$(echo $extra_inputs | base64 -d)
export inputs_json="$(echo $extra_inputs | base64 -d | jq -r '.["extra_inputs"]')"
http_code=$(curl --request PUT -s -o output.json -w '%{http_code}' "$put_workflow_url" --header "Authorization: Bearer $secret_stk_login" --header 'Content-Type: application/json' --data "$(echo $extra_inputs | base64 -d)";)
if [[ "$http_code" -ne "200" ]]; then
echo "HTTP_CODE:" $http_code
echo "RESPONSE_CONTENT:" $(cat output.json)
exit $http_code
fi
url="$workflow_api_base_url/workflows/$execution_id?loginType=CLIENT_ACCESS"
if [[ "$origin_branch" != "" ]]; then
url="$url&originBranch=$origin_branch"
fi
if [[ "$feature_branch" != "" ]]; then
url="$url&featureBranch=$feature_branch"
fi
http_code=$(curl -s -o script.sh -w '%{http_code}' "$url" --header "Authorization: Bearer $secret_stk_login";)
if [[ "$http_code" -ne "200" ]]; then
echo "HTTP_CODE:" $http_code
echo "RESPONSE_CONTENT:"
cat script.sh
exit 1
else
chmod +x script.sh
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Starting ----------------------------------------"
echo "------------------------------------------------------------------------------------------"
echo "{\"outputs\": {\"created_repository\": \"$repo_url\"}}" > stk-local-context.json
bash script.sh
result=$?
if [[ "$debug" == "true" ]]; then
cat ~/.stk/debug/http.txt
fi
echo "------------------------------------------------------------------------------------------"
echo "---------------------------------------- Ending ----------------------------------------"
echo "------------------------------------------------------------------------------------------"
exit $result
fi