@@ -28,9 +28,13 @@ def add_jenkins_repository():
28
28
29
29
30
30
def configure_jenkins (repo ):
31
- """
31
+ """Configure the jenkins json file.
32
+
32
33
We have to update the json file if we want to switch between distribution
33
- provided jenkins and upstream jenkins
34
+ provided jenkins and upstream jenkins.
35
+
36
+ :param repo: A repository to use.
37
+ :type repo: str
34
38
"""
35
39
command1 = 'curl -L http://updates.jenkins-ci.org/update-center.json'
36
40
command2 = 'sed "1d;$d" > /var/lib/jenkins/updates/default.json'
@@ -44,13 +48,15 @@ def configure_jenkins(repo):
44
48
45
49
@task
46
50
def deploy_jenkins_plugins (repo ):
47
- """
51
+ """Set up jenkins plugins post-installation.
52
+
48
53
Deploying plugins with jenkins-cli seems not to be reliable
49
54
For now if the plugins are not getting installed automatically
50
55
we have to go to the webinterface and install at least github and xvfb
51
- plugin manually before calling setup_jenkins_jobs
56
+ plugin manually before calling setup_jenkins_jobs.
57
+
52
58
:param repo: repository to use
53
- :return:
59
+ :type repo: str
54
60
"""
55
61
webpath = 'http://updates.jenkins-ci.org'
56
62
distribution = repo
@@ -114,13 +120,12 @@ def install_jenkins(use_upstream_repo=False):
114
120
some of the plugins listed in the configure_jenkins target may not
115
121
install.
116
122
117
- Args:
118
- use_upstream_repo - bool: (defaults to False). Whether to use the
119
- official jenkins repo or not. In the case of False,
120
- the distribution repo version will be used instead.
123
+ :param use_upstream_repo: Whether to use the official jenkins repo or not.
124
+ In the case of False, the distribution repo version will be used
125
+ instead. Defaults to False.
126
+
127
+ Example using the upstream jenkins repo::
121
128
122
- Example:
123
- Using the upstream jenkins repo:
124
129
fab -H localhost fabgis.fabgis.install_jenkins:use_upstream_repo=True
125
130
126
131
"""
@@ -154,21 +159,24 @@ def install_jenkins(use_upstream_repo=False):
154
159
155
160
156
161
@task
157
- def jenkins_deploy_website (site_url = None , use_upstream_repo = False ):
162
+ def jenkins_deploy_website (site_url = None ):
158
163
"""
159
164
Initialise jenkins with local proxy if we are not going to use port
160
165
8080
166
+
167
+ :param site_url: Name of the web site.
168
+ :type site_url: str
161
169
"""
162
170
setup_env ()
163
171
fabtools .require .deb .package ('apache2' )
164
- sitename = site_url
172
+ site_name = site_url
165
173
166
- if not sitename :
167
- sitename = 'jenkins'
174
+ if not site_name :
175
+ site_name = 'jenkins'
168
176
else :
169
- sitename = site_url
177
+ site_name = site_url
170
178
171
- jenkins_apache_conf = ('fabgis.%s.conf' % ( sitename ) )
179
+ jenkins_apache_conf = ('fabgis.%s.conf' % site_name )
172
180
jenkins_apache_conf_template = 'fabgis.jenkins.conf.templ'
173
181
174
182
with cd ('/etc/apache2/sites-available/' ):
@@ -189,15 +197,15 @@ def jenkins_deploy_website(site_url=None, use_upstream_repo=False):
189
197
my_tokens = {
190
198
'SERVERNAME' : env .fg .hostname , # Web Url e.g. foo.com
191
199
'WEBMASTER' :
'[email protected] ' ,
# email of web master
192
- 'SITENAME' : sitename , # Choosen name of jenkins 'root'
200
+ 'SITENAME' : site_name , # Choosen name of jenkins 'root'
193
201
}
194
202
replace_tokens (jenkins_apache_conf_template , my_tokens )
195
203
196
204
# Add a hosts entry for local testing - only really useful for localhost
197
205
hosts = '/etc/hosts'
198
- if not contains (hosts , '%s.%s' % (sitename , env .fg .hostname )):
206
+ if not contains (hosts , '%s.%s' % (site_name , env .fg .hostname )):
199
207
append_if_not_present (hosts ,
200
- '127.0.1.1 %s.%s' % (sitename , env .fg .hostname ),
208
+ '127.0.1.1 %s.%s' % (site_name , env .fg .hostname ),
201
209
use_sudo = True )
202
210
append_if_not_present (hosts ,
203
211
'127.0.0.1 %s.localhost' % env .fg .hostname ,
@@ -207,3 +215,38 @@ def jenkins_deploy_website(site_url=None, use_upstream_repo=False):
207
215
sudo ('a2enmod proxy_http' )
208
216
sudo ('a2ensite %s' % jenkins_apache_conf )
209
217
sudo ('service apache2 reload' )
218
+
219
+ @task
220
+ def setup_jenkins_jobs (jobs , job_directory_path ):
221
+ """Setup jenkins to run Continuous Integration Tests.
222
+
223
+ :param jobs: A list of job names to create.
224
+
225
+ :param job_directory_path: Directory containing jenkins xml job
226
+ definition files.
227
+
228
+ """
229
+ #fabgis.fabgis.initialise_jenkins_site()
230
+ xvfb_config = "org.jenkinsci.plugins.xvfb.XvfbBuildWrapper.xml"
231
+
232
+ with cd ('/var/lib/jenkins/' ):
233
+ if not exists (xvfb_config ):
234
+ local_file = os .path .abspath (os .path .join (
235
+ job_directory_path ,
236
+ 'jenkins_jobs' ,
237
+ xvfb_config ))
238
+ put (local_file ,
239
+ "/var/lib/jenkins/" , use_sudo = True )
240
+
241
+ with cd ('/var/lib/jenkins/jobs/' ):
242
+ for job in jobs :
243
+ if not exists (job ):
244
+ local_job_file = os .path .abspath (os .path .join (
245
+ job_directory_path ,
246
+ '%s.xml' % job ))
247
+ sudo ('mkdir /var/lib/jenkins/jobs/%s' % job )
248
+ put (local_job_file ,
249
+ "/var/lib/jenkins/jobs/%s/config.xml" % job ,
250
+ use_sudo = True )
251
+ sudo ('chown -R jenkins:nogroup InaSAFE*' )
252
+ sudo ('service jenkins restart' )
0 commit comments