forked from rik2803/bb-aws-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync_trigger_bb_build.bash
executable file
·61 lines (47 loc) · 1.75 KB
/
sync_trigger_bb_build.bash
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
#! /bin/bash
echo "### Starting $(basename "${0}") ###"
### Install jq
scriptdir=$(dirname "${0}")
source ${scriptdir}/lib.bash
echo "### Start jq installation ###"
install_jq
### jq is required
if ! which jq >/dev/null 2>&1
then
echo "### jq is required ###"
exit 1
else
echo "### jq is installed ###"
fi
[[ -z ${REMOTE_REPO_SLUG} ]] && { echo "REMOTE_REPO_SLUG is required"; exit 1; }
[[ -z ${REMOTE_REPO_OWNER} ]] && { echo "REMOTE_REPO_OWNER is required"; exit 1; }
[[ -z ${BB_USER} ]] && { echo "BB_USER is required"; exit 1; }
[[ -z ${BB_APP_PASSWORD} ]] && { echo "BB_APP_PASSWORD is required"; exit 1; }
export URL="https://api.bitbucket.org/2.0/repositories/${REMOTE_REPO_OWNER}/${REMOTE_REPO_SLUG}/pipelines/"
echo "### REMOTE_REPO_OWNER: ${REMOTE_REPO_OWNER} ###"
echo "### REMOTE_REPO_SLUG: ${REMOTE_REPO_SLUG} ###"
echo "### URL: ${URL} ###"
CURLRESULT=$(curl -X POST -s -u "${BB_USER}:${BB_APP_PASSWORD}" -H 'Content-Type: application/json' \
${URL} -d '{ "target": { "ref_type": "branch", "type": "pipeline_ref_target", "ref_name": "master" } }')
UUID=$(echo "${CURLRESULT}" | jq --raw-output '.uuid' | tr -d '\{\}')
echo "UUID is ${UUID}"
CONTINUE=1
SLEEP=10
STATE="NA"
RESULT="na"
CURLRESULT="NA"
while [[ ${CONTINUE} = 1 ]]
do
sleep ${SLEEP}
CURLRESULT=$(curl -X GET -s -u "${BB_USER}:${BB_APP_PASSWORD}" -H 'Content-Type: application/json' ${URL}\\{${UUID}\\})
STATE=$(echo ${CURLRESULT} | jq --raw-output '.state.name')
echo " ### Pipeline is in state ${STATE} ###"
if [[ ${STATE} == "COMPLETED" ]]
then
CONTINUE=0
fi
done
RESULT=$(echo ${CURLRESULT} | jq --raw-output '.state.result.name')
echo " ### Pipeline result is ${RESULT} ###"
[[ ${RESULT} == "SUCCESSFUL" ]] && exit 0
exit 1