-
Notifications
You must be signed in to change notification settings - Fork 2
/
jenkins
executable file
·156 lines (138 loc) · 3.93 KB
/
jenkins
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
#+
# Use this script to trigger a build on a Jenkins server for the working branch.
#-
source scripts/mistify-functions.sh
usage () {
cat << EOF
Usage: $0 [options] [-- joboptions]
Use this script to remotely trigger a Mistify build on a Jenkins CI server.
The Jenkins CI server must be configured to run the buildmistify script on the
server in order to build.
Options:
==== remote build ====
--jenkins <url>
The Jenkins CI server URL. The URL is saved in the file
$statedir/jenkins.
[jenkins=$jenkinsdefault]
--job <job>
The job to execute. This must match a name in the Jenkins job list. This
is saved in the file: $statedir/jenkinsjob
[job=$jenkinsjobdefault]
--mistifybranch <branch>
The Mistify-OS branch or tag to checkout for the build.
This is saved in the file: $statedir/jenkinsmistifybranch
[mistifybranch=$jenkinsmistifybranchdefault]
-- <joboptions>
Anything following the "--" is passed directly to the Jenkins server.
This can be additional options to pass to a script or a complete
command line depending upon how the job is configured on the server. The
job needs to be configured to accept a parameter named "mistify_job_options".
Parameters passed to the Jenkins server:
[mistify_branch=$mistifybranch]
[mistify_job_options=<joboptions>]
==== other ====
--resetdefaults
Reset options back to their default values.
--dryrun
Just testing what will happen with this script. Don't send anything to
the Jenkins server and instead display the command.
-h|--help
Display this usage.
NOTE: This script maintains state in $statedir.
EOF
}
#+
# Handle the command line options.
#-
a=`getopt -l "\
jenkins:,\
job:,\
resetdefaults,\
dryrun,\
help" \
-o "h" -- "$@"`
if [ $? -gt 0 ]; then
usage
exit 1
fi
eval set -- $a
while [ $# -ge 1 ]; do
case "$1" in
--)
shift
mistify_job_options=$*
break
;;
--jenkins)
jenkins=$2
shift
;;
--job)
jenkinsjob=$2
shift
;;
--mistifybranch)
jenkinsmistifybranch=$2
shift
;;
--resetdefaults)
resetdefaults=y
;;
--dryrun)
dryrun=echo
;;
-h|--help)
showusage=y
;;
# using getopt should avoid needing this catchall but just in case...
*)
error "Invalid option: $1"
usage
exit 1
;;
esac
shift
done
if [ ! -z "$resetdefaults" ]; then
reset_build_default jenkins
reset_build_default jenkinsjob
reset_build_default jenkinsmistifybranch
fi
jenkinsdefault=$(get_build_default jenkins http://mistify-dev-2.office.omniti.com:8081)
jenkinsjobdefault=$(get_build_default jenkinsjob MistifyOS-remote)
jenkinsmistifybranchdefault=$(get_build_default jenkinsmistifybranch $mistifybranch)
if [ -z "$jenkins" ]; then
jenkins=$jenkinsdefault
fi
if [ -z "$jenkinsjob" ]; then
jenkinsjob=$jenkinsjobdefault
fi
if [ -z "$jenkinsmistifybranch" ]; then
jenkinsmistifybranch=$jenkinsmistifybranchdefault
fi
if [ ! -z "$showusage" ]; then
usage
exit 0
fi
if [ -n "$mistify_job_options" ]; then
message "Options are: $mistify_job_options"
params="&mistify_job_options="
params+=`echo $mistify_job_options | sed 's/ /%20/g'`
message "Adding Jenkins parameters: $params"
fi
jenkinscommand="wget -O /dev/null $jenkins/job/$jenkinsjob/buildWithParameters?token=buildmistify&mistify_branch=$jenkinsmistifybranch$params"
if [ -n "$dryrun" ]; then
message "Just a test run -- not building."
else
set_build_default jenkins $jenkins
set_build_default jenkinsjob $jenkinsjob
set_build_default jenkinsmistifybranch $jenkinsmistifybranch
fi
message "Triggering a remote build on Jenkins server: $jenkins"
message "The branch is: $jenkinsmistifybranch"
$dryrun $jenkinscommand
if [ $? -gt 0 ]; then
error The Jenkins server is not running at the URL or did not accept the job.
exit 1
fi