Commit 7d45f1f9 authored by bertagaz's avatar bertagaz
Browse files

Update automated build jobs generator script.

Configure the BuildTailsISOJob object on initialization.
parent 176924a9
......@@ -2,68 +2,42 @@
import yaml
TAILS_RM_EMAIL = 'tails-rm@boum.org'
JOB_TEMPLATE = '''- job:
node: isobuilder1 || isobuilder2
builders:
- build_Tails_ISO
- clean_Archives
triggers:
- pollscm: '@weekly'
- timed: '@daily'
wrappers:
- timestamps
- workspace-cleanup:
dirmatch: true
include:
- "**"'''
class BuildTailsISOJob:
TAILS_RM_EMAIL = 'tails-rm@boum.org'
DESCRIPTION_TEMPLATE = \
'''<p>This job is managed by jenkins-job-builder. Do not edit it through this web interface, your changes would be overwritten.</p>
<p>You can <a href="http://nightly.tails.boum.org/%s/">download build results</a>.</p>'''
def __init__(self, **entries):
self.__dict__.update(entries)
def __str__(self):
return yaml.safe_dump([self.__dict__], default_flow_style=False)
def configure(self, branch):
"""Configure the jenkins job according to the branch info
given as parameter."""
self._set_name(branch['job_name'])
self._set_git_config(branch['branch_name'])
if branch['base_branch']:
self._set_email_publisher_recipients(TAILS_RM_EMAIL)
else:
self._set_email_publisher_recipients(branch['recipients'])
self._set_description()
def _set_name(self, job_name):
"""Set the job name."""
self.job['name'] = "build_Tails_ISO_" + job_name
def _set_git_config(self, branch_name):
"""Set the git configuration for the job."""
def __init__(self, snippet, branch):
assert type(branch['branch_name']) is str
assert branch['branch_name'].__len__() > 0
assert type(branch['job_name']) is str
assert branch['job_name'].__len__() > 0
assert type(branch['base_branch']) is bool
assert type(branch['recipients']) is str
assert branch['recipients'].__len__() > 0
assert type(snippet) is str
assert snippet.__len__() > 0
base = yaml.safe_load(snippet)
self.__dict__.update(**base[0])
self.job['name'] = "build_Tails_ISO_" + branch['job_name']
self.job['scm'] = [{'git': \
{'branches': [branch_name],
{'branches': [branch['branch_name']],
'browser': 'cgit',
'browser-url': 'https://git-tails.immerda.ch/tails/',
'url': 'gitolite@puppet-git.lizard:tails'}
}]
def _set_email_publisher_recipients(self, emails):
"""Set the recipients for the job email publisher."""
self.job['publishers'] = [{'email': { 'recipients': emails}}]
def _set_description(self):
"""Set the description of the job."""
if branch['base_branch']:
self.job['publishers'] = [{'email': { 'recipients': self.TAILS_RM_EMAIL}}]
else:
self.job['publishers'] = [{'email': { 'recipients': branch['recipients']}}]
self.job['description'] = self.DESCRIPTION_TEMPLATE % self.job['name']
def __str__(self):
return yaml.safe_dump([self.__dict__], default_flow_style=False)
def get_active_branches():
"""Retrieve the list of active branches using the Tails python library.
......@@ -71,7 +45,7 @@ def get_active_branches():
return [{'branch_name': 'feature/test_active_branch_job',
'job_name': 'feature-test_active_branch_job',
'base_branch': False,
'recipients': 'test@alors.org test2@alors.org'},
'recipients': 'test@test test2@test'},
{'branch_name': 'bugfix/there_should_be_two_of_them',
'job_name': 'bugfix-there_should_be_two_of_them',
'base_branch': True,
......@@ -79,11 +53,24 @@ def get_active_branches():
]
JOB_SNIPPET = '''- job:
node: isobuilder1 || isobuilder2
builders:
- build_Tails_ISO
- clean_Archives
triggers:
- pollscm: '@weekly'
- timed: '@daily'
wrappers:
- timestamps
- workspace-cleanup:
dirmatch: true
include:
- "**"'''
if __name__ == "__main__":
for branch in get_active_branches():
job_template = yaml.safe_load(JOB_TEMPLATE)
job = BuildTailsISOJob(**job_template[0])
job.configure(branch)
job = BuildTailsISOJob(JOB_SNIPPET, branch)
job_filename = "%s.yaml" % branch['job_name']
with open(job_filename, 'w') as job_file:
job_file.write(str(job))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment