forked from molior-dbs/molior-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmolior-trigger
executable file
·58 lines (45 loc) · 1.12 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
#!/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 --cookie "$COOKIE_FILE" --cookie-jar "$COOKIE_FILE" "$@"
}
# login to the molior session
molior_session_call "$MOLIOR_URL/plogin" \
--data-urlencode "username=$MOLIOR_USER" \
--data-urlencode "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`
token=`echo $response | jq -r '.build_token'`
if [ -z "$token" ]; then
echo Error triggering build
exit 1
fi
echo "Build triggered: token=$token"
echo
echo "Query build state with: "
echo "curl -s $MOLIOR_URL/api/build/$token | json_pp"
echo