Commit 176924a9 authored by bertagaz's avatar bertagaz
Browse files

Import automated build jobs generator script.

parent daab432c
#!/usr/bin/python3
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:
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."""
self.job['scm'] = [{'git': \
{'branches': [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."""
self.job['description'] = self.DESCRIPTION_TEMPLATE % self.job['name']
def get_active_branches():
"""Retrieve the list of active branches using the Tails python library.
Now is just a stub returning a list of branch dict."""
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'},
{'branch_name': 'bugfix/there_should_be_two_of_them',
'job_name': 'bugfix-there_should_be_two_of_them',
'base_branch': True,
'recipients': 'test@alors.org'}
]
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_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