-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjenkins
More file actions
executable file
·189 lines (171 loc) · 4.78 KB
/
jenkins
File metadata and controls
executable file
·189 lines (171 loc) · 4.78 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#!/bin/bash
#+
# Use this script to trigger a build on a Jenkins server for the working branch.
#-
source scripts/mistify-test-functions.sh
usage () {
cat << EOF
Usage: $0 [options] [-- testmistifyoptions]
Use this script to remotely trigger a Mistify test run on a Jenkins CI server.
This can be a series of tests against and existing build or tests which are
designed to verify the build process using a container.
The Jenkins CI server must be configured to run the testmistify script on the
server in order to run tests.
Options:
==== remote test ====
--jenkins <url>
The Jenkins CI server URL. The URL is saved in the file:
$testmistifystatedir/jenkins.
[jenkins=$jenkins]
--jenkinsjob <job>
The job to execute. This must match a name in the Jenkins job list. This
is saved in the file:
$testmistifystatedir/jenkinsjob
[jenkinsjob=$jenkinsjob]
--mistifytestbranch <branch>
The Mistify-test branch or tag to checkout for the test run.
This is saved in the file:
$testmistifystatedir/mistifytestbranch
[mistifytestbranch=$mistifytestbranch]
--jenkinsuser <user>[:<password>]
Use to start a build on a Jenkins server which requires authentication.
This is the user name and an optional password.
This is not saved.
--testoptions "<options>"
Options to be passed directly to the test scripts. This is not saved.
The job needs to be configured to accept a parameter named "test_options".
-- <testmistifyoptions>
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 "testmistify_options".
Parameters passed to the Jenkins server:
[mistify_test_branch=$mistifytestbranch]
[testmistify_options=<testmistifyoptions>]
==== other ====
--resetdefaults
Reset options back to their default values.
--verbose
Verbose output from this script.
--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 $testmistifystatedir.
EOF
}
#+
# Handle the command line options.
#-
a=`getopt -l "\
jenkins:,\
jenkinsjob:,\
mistifytestbranch:,\
jenkinsuser:,\
jenkinspassword:,\
testoptions:,\
resetdefaults,\
verbose,\
dryrun,\
help" \
-o "h" -- "$@"`
if [ $? -gt 0 ]; then
usage
exit 1
fi
eval set -- $a
while [ $# -ge 1 ]; do
case "$1" in
--)
shift
testmistifyoptions=$*
break
;;
--jenkins)
jenkins=$2
shift
;;
--jenkinsjob)
jenkinsjob=$2
shift
;;
--mistifytestbranch)
mistifytestbranch=$2
shift
;;
--jenkinsuser)
jenkinsuser=$2
shift
;;
--testoptions)
testoptions=$2
shift
;;
--resetdefaults)
resetdefaults=y
;;
--verbose)
verbose=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
verbose The Mistify test branch default is: $mistifytestbranchdefault
statevars=(
jenkins\;http://mistify-dev-2.office.omniti.com:8081
jenkinsjob\;MistifyTest-remote
mistifytestbranch\;$mistifytestbranchdefault
)
for v in "${statevars[@]}"
do
if [ ! -z "$resetdefaults" ]; then
clear_test_variable $v
fi
init_test_variable $v
done
verbose The Mistify test branch is: $mistifytestbranch
if [ ! -z "$showusage" ]; then
usage
exit 0
fi
if [ -n "$testmistifyoptions" ]; then
message "Options passed to testmistify are: $testmistifyoptions"
params="&testmistify_options="
params+=`echo $testmistifyoptions | sed 's/ /%20/g'`
message "Adding Jenkins parameters: $params"
fi
if [ -n "$testoptions" ]; then
message "Test options are: $testoptions"
params+="&test_options="
params+=`echo $testoptions | sed 's/ /%20/g'`
fi
if [ -n "$jenkinsuser" ]; then
auth=" --user $jenkinsuser"
fi
jenkinscommand="curl -XPOST \"$jenkins/job/$jenkinsjob/buildWithParameters"
jenkinscommand+="?token=testmistify"
jenkinscommand+="&mistify_test_branch=$mistifytestbranch$params\""
jenkinscommand+=$auth
if [ -n "$dryrun" ]; then
message "Just a test run -- not building."
fi
message "Triggering a remote build on Jenkins server: $jenkins"
message "The branch is: $mistfiytestbranch"
$dryrun eval $jenkinscommand
if [ $? -gt 0 ]; then
error The Jenkins server is not running at the URL or did not accept the job.
exit 1
fi