generate_build_tails_iso_jobs.py 2.31 KB
Newer Older
1
2
3
4
5
6
#!/usr/bin/python3

import yaml

class BuildTailsISOJob:

7
8
    TAILS_RM_EMAIL = 'tails-rm@boum.org'

9
10
11
12
    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>'''

13
14
15
16
17
18
19
20
    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(snippet) is str
        assert snippet.__len__() > 0
21
        self.job = yaml.safe_load(snippet)
22
        self.job['name'] = "build_Tails_ISO_" + branch['job_name']
23
        self.job['scm'] = [{'git': \
24
                {'branches': [branch['branch_name']],
25
26
27
28
                 'browser': 'cgit',
                 'browser-url': 'https://git-tails.immerda.ch/tails/',
                 'url': 'gitolite@puppet-git.lizard:tails'}
                }]
29
30
        if branch['base_branch']:
            self.job['publishers'] = [{'email': { 'recipients': self.TAILS_RM_EMAIL}}]
31

32
    def __str__(self):
33
        return yaml.safe_dump([{'job': self.job}], default_flow_style=False)
34

35
36
37
38
39
40
41

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,
intrigeri's avatar
intrigeri committed
42
            },
43
44
45
            {'branch_name': 'bugfix/there_should_be_two_of_them',
             'job_name': 'bugfix-there_should_be_two_of_them',
             'base_branch': True,
intrigeri's avatar
intrigeri committed
46
            },
47
48
49
           ]


50
51
52
53
54
55
56
57
58
59
60
61
62
JOB_SNIPPET = '''node: isobuilder1 || isobuilder2
builders:
  - build_Tails_ISO
  - clean_Archives
triggers:
  - pollscm: '@weekly'
  - timed: '@daily'
wrappers:
  - timestamps
  - workspace-cleanup:
      dirmatch: true
      include:
        - "**"'''
63

64
65
if __name__ == "__main__":
    for branch in get_active_branches():
66
        job = BuildTailsISOJob(JOB_SNIPPET, branch)
67
68
69
70
        job_filename = "%s.yaml" % branch['job_name']
        with open(job_filename, 'w') as job_file:
            job_file.write(str(job))