Skip to content

Commit 6501137

Browse files
committed
Added config file for jenkins loading (in progress)
1 parent fd53d33 commit 6501137

File tree

1 file changed

+63
-20
lines changed

1 file changed

+63
-20
lines changed

fabgis/jenkins.py

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ def add_jenkins_repository():
2828

2929

3030
def configure_jenkins(repo):
31-
"""
31+
"""Configure the jenkins json file.
32+
3233
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
3438
"""
3539
command1 = 'curl -L http://updates.jenkins-ci.org/update-center.json'
3640
command2 = 'sed "1d;$d" > /var/lib/jenkins/updates/default.json'
@@ -44,13 +48,15 @@ def configure_jenkins(repo):
4448

4549
@task
4650
def deploy_jenkins_plugins(repo):
47-
"""
51+
"""Set up jenkins plugins post-installation.
52+
4853
Deploying plugins with jenkins-cli seems not to be reliable
4954
For now if the plugins are not getting installed automatically
5055
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+
5258
:param repo: repository to use
53-
:return:
59+
:type repo: str
5460
"""
5561
webpath = 'http://updates.jenkins-ci.org'
5662
distribution = repo
@@ -114,13 +120,12 @@ def install_jenkins(use_upstream_repo=False):
114120
some of the plugins listed in the configure_jenkins target may not
115121
install.
116122
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::
121128
122-
Example:
123-
Using the upstream jenkins repo:
124129
fab -H localhost fabgis.fabgis.install_jenkins:use_upstream_repo=True
125130
126131
"""
@@ -154,21 +159,24 @@ def install_jenkins(use_upstream_repo=False):
154159

155160

156161
@task
157-
def jenkins_deploy_website(site_url=None, use_upstream_repo=False):
162+
def jenkins_deploy_website(site_url=None):
158163
"""
159164
Initialise jenkins with local proxy if we are not going to use port
160165
8080
166+
167+
:param site_url: Name of the web site.
168+
:type site_url: str
161169
"""
162170
setup_env()
163171
fabtools.require.deb.package('apache2')
164-
sitename = site_url
172+
site_name = site_url
165173

166-
if not sitename:
167-
sitename = 'jenkins'
174+
if not site_name:
175+
site_name = 'jenkins'
168176
else:
169-
sitename = site_url
177+
site_name = site_url
170178

171-
jenkins_apache_conf = ('fabgis.%s.conf' % (sitename))
179+
jenkins_apache_conf = ('fabgis.%s.conf' % site_name)
172180
jenkins_apache_conf_template = 'fabgis.jenkins.conf.templ'
173181

174182
with cd('/etc/apache2/sites-available/'):
@@ -189,15 +197,15 @@ def jenkins_deploy_website(site_url=None, use_upstream_repo=False):
189197
my_tokens = {
190198
'SERVERNAME': env.fg.hostname, # Web Url e.g. foo.com
191199
'WEBMASTER': '[email protected]', # email of web master
192-
'SITENAME': sitename, # Choosen name of jenkins 'root'
200+
'SITENAME': site_name, # Choosen name of jenkins 'root'
193201
}
194202
replace_tokens(jenkins_apache_conf_template, my_tokens)
195203

196204
# Add a hosts entry for local testing - only really useful for localhost
197205
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)):
199207
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),
201209
use_sudo=True)
202210
append_if_not_present(hosts,
203211
'127.0.0.1 %s.localhost' % env.fg.hostname,
@@ -207,3 +215,38 @@ def jenkins_deploy_website(site_url=None, use_upstream_repo=False):
207215
sudo('a2enmod proxy_http')
208216
sudo('a2ensite %s' % jenkins_apache_conf)
209217
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

Comments
 (0)