-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmolior-trigger
executable file
·59 lines (46 loc) · 1.17 KB
/
molior-trigger
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
#!/bin/sh
set -e
. /usr/lib/molior-tools/molior.sh.inc
PROGRAMM_NAME="$0"
usage()
{
ERROR="$1"
echo "Usage: $PROGRAMM_NAME ssh://REPOSIROTY_URL [GIT_REF] [GIT_BRANCH]"
if [ -n "$ERROR" ]; then
echo
echo "$ERROR"
fi
exit 1
}
REPO=$1
if [ -z "$REPO" ]
then
usage "You have to specify a git repo!"
fi
GIT_REF=$2
GIT_BRANCH=$3
aquire_user
aquire_pass
COOKIE_FILE=`mktemp`
molior_session_call()
{
curl -s --retry 10 --cookie "$COOKIE_FILE" --cookie-jar "$COOKIE_FILE" "$@"
}
# login to the molior session
molior_session_call "$MOLIOR_URL/api/login" \
--header "Content-Type: application/json" \
--request POST \
--data "{\"username\": \"$MOLIOR_USER\", \"password\": \"$MOLIOR_PASSWORD\"}" \
--location > /dev/null
response=`molior_session_call --header "Content-Type: application/json" --request POST \
--data "{\"repository\": \"$REPO\", \"git_ref\": \"$GIT_REF\", \"git_branch\": \"$GIT_BRANCH\"}" $MOLIOR_URL/api/build`
ID=`echo $response | jq -r '.build_id'`
if [ -z "$ID" ]; then
echo Error triggering build
exit 1
fi
echo "Build triggered: $ID"
echo
echo "Query build state with: "
echo "curl -s --retry 10 $MOLIOR_URL/api/build/$ID | json_pp"
echo