-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdrone.sh
executable file
·65 lines (62 loc) · 2.06 KB
/
drone.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
#!/bin/bash
if test "${PLUGIN_REPOSITORIES:-}" = ""; then
echo "missing PLUGIN_REPOSITORIES env var"
echo "=> miss repositories value in configuration ?"
exit 1
fi
if test "${DOWNSTREAM_SERVER:-}" != ""; then
if test "${DRONE_SERVER:-}" = ""; then
export DRONE_SERVER=${DOWNSTREAM_SERVER}
fi
fi
if test "${DOWNSTREAM_TOKEN:-}" != ""; then
if test "${DRONE_TOKEN:-}" = ""; then
export DRONE_TOKEN=${DOWNSTREAM_TOKEN}
fi
fi
if test "${DRONE_SERVER:-}" = ""; then
echo "missing DRONE_SERVER env var"
echo "=> miss downstream_server secret in configuration ?"
exit 1
fi
if test "${DRONE_TOKEN:-}" = ""; then
echo "missing DRONE_TOKEN env var"
echo "=> miss downstream_token secret in configuration ?"
exit 1
fi
if test -f .drone_downstream_bypass; then
echo "downstream bypass"
exit 0
fi
for REPO in $(echo "${PLUGIN_REPOSITORIES}" |sed 's/,/ /g'); do
REPO_NAME=$(echo "${REPO}" |awk -F '@' '{print $1;}')
BRANCH_NAME=$(echo "${REPO}" |awk -F '@' '{print $2;}')
if test "${BRANCH_NAME:-}" = ""; then
BRANCH_NAME=master
fi
echo "Working on REPO_NAME=${REPO_NAME} and BRANCH=${BRANCH_NAME}..."
LAST=$(drone build last --branch="${BRANCH_NAME}" "${REPO_NAME}")
if test $? -ne 0; then
echo "can't find last build for repo:${REPO_NAME} and branch:${BRANCH_NAME}"
exit 1
fi
LAST_BUILD=$(echo "${LAST}" |head -1 |awk '{print $2;}')
if test "${LAST_BUILD}" = ""; then
echo "can't find last build for repo:${REPO_NAME} and branch:${BRANCH_NAME}"
echo "raw last output: ${LAST}"
exit 1
fi
echo "Last build: ${LAST_BUILD}"
PARAM_ARGS=""
if test "${PLUGIN_PARAMS}" != ""; then
for PARAM in $(echo "${PLUGIN_PARAMS}" |sed 's/,/ /g'); do
PARAM_ARGS="--param ${PARAM} ${PARAM_ARGS}"
done
fi
echo "Restarting build ${LAST_BUILD} with param args: ${PARAM_ARGS}"
drone build start ${PARAM_ARGS} ${REPO_NAME} ${LAST_BUILD}
if test $? -ne 0; then
echo "ERROR during drone build start"
exit 1
fi
done