generate_build_tails_iso_jobs 2.43 KB
Newer Older
1
2
3
4
#!/usr/bin/python3

import yaml

5
TAILS_RM_EMAIL = 'tails-rm@boum.org'
6

7
class BuildTailsISOJob:
8

9
10
    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>
11
<p>You can <a href="http://nightly.tails.boum.org/%(job_name)s/">download build results</a>.</p>'''
12

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    JOB_SNIPPET = '''node: isobuilder1 || isobuilder2
builders:
  - build_Tails_ISO
  - clean_Archives
triggers:
  - pollscm: '@weekly'
  - timed: '@daily'
wrappers:
  - timestamps
  - workspace-cleanup:
      dirmatch: true
      include:
        - "**"'''

    def __init__(self, branch, snippet = JOB_SNIPPET):
28
29
30
31
32
33
34
        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
35
        self.job = yaml.safe_load(snippet)
36
        self.job['name'] = "build_Tails_ISO_" + branch['job_name']
37
        self.job['scm'] = [{'git': \
38
                {'branches': [branch['branch_name']],
39
40
41
42
                 'browser': 'cgit',
                 'browser-url': 'https://git-tails.immerda.ch/tails/',
                 'url': 'gitolite@puppet-git.lizard:tails'}
                }]
43
        if branch['base_branch']:
44
            self.job['publishers'] = [{'email': { 'recipients': TAILS_RM_EMAIL}}]
45
46
47
        self.job['description'] = self.DESCRIPTION_TEMPLATE % {
            'job_name': self.job['name']
        }
48

49
    def __str__(self):
50
        return yaml.safe_dump([{'job': self.job}], default_flow_style=False)
51

52
53
54
55
56
57
58

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
59
            },
60
61
62
            {'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
63
            },
64
65
66
67
           ]

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