diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-09-22 01:31:54 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-09-22 01:31:54 +0100 |
commit | e07a57a1816564918dcb5ca82cf86bcb069f52f9 (patch) | |
tree | 76d7388e1de5110583da62c723913d602dc0d8bc /jenkinstool | |
parent | fbd79331a11cb6a83097aa2b727325824cef4eb5 (diff) | |
download | jenkinstool-e07a57a1816564918dcb5ca82cf86bcb069f52f9.tar.gz |
Generate trigger-less jobs, and run them
Diffstat (limited to 'jenkinstool')
-rwxr-xr-x | jenkinstool | 96 |
1 files changed, 35 insertions, 61 deletions
diff --git a/jenkinstool b/jenkinstool index e63f33b..2ddecad 100755 --- a/jenkinstool +++ b/jenkinstool @@ -203,16 +203,14 @@ class JobGenerator(object): self.artifacts_url = artifacts_url self.jenkins_host = jenkins_host - def generate(self, config): - '''Generate all the jobs for a given config. + def generate_setup_jobs(self, config): + '''Generate all the shared jobs to setup Jenkins. - Yield (job_id, config_xml) tuples. + Return list of (job_id, config_xml) pairs. ''' - # Create a job to trigger all other jobs. - a1trigger = self.trigger_everything_job(config) - jobs = [a1trigger] + jobs = [] # Setup reprepro on Jenkins host. reprepro = self.reprepro_setup_job(config) @@ -223,44 +221,8 @@ class JobGenerator(object): jc = self.pbuilder_create_job(host) jobs.append(jc) - # Trigger all project pipelines. - trigger = self.trigger_projects_job(config) - jobs.append(trigger) - - # Create a pipeline for each project. Every job in the pipeline - # triggers the next job. The first job is not triggered yet, - # we set up that later. - pipelines = {} - for project in config['projects']: - prev = None - for jc in self.generate_project(config, project): - if prev: - pipelines[project['name']].append(jc) - else: - pipelines[project['name']] = [jc] - prev = jc - jobs.append(jc) - return [(jc.job_id(), jc.tostring()) for jc in jobs] - def trigger_everything_job(self, config): - '''Create job that triggers every other job.''' - - host = config['hosts'][0] - project = {'name': 'a1_trigger'} - jc = self.create_job_config(host, project, 'trigger') - jc.set_description('A1 Trigger All Jobs') - return jc - - def trigger_projects_job(self, config): - '''Create job that triggers pipelines for projects.''' - - host = config['hosts'][0] - project = {'name': 'a2_trigger_projects'} - jc = self.create_job_config(host, project, 'trigger') - jc.set_description('A2 Project Trigger') - return jc - def reprepro_setup_job(self, config): '''Create job that sets up reprepro.''' @@ -423,7 +385,7 @@ setup_pbuilder "$pbuilder_release_tgz" "" jobs.append(self.process_incoming_job( config, localhost, project, 'deb_%s' % host['name'])) - return jobs + return [(jc.job_id(), jc.tostring()) for jc in jobs] def vcs_watch_job(self, host, project): '''Generate a job watch a VCS repository.''' @@ -752,33 +714,45 @@ class JenkinsTool(cliapp.Application): jenkins = simplejenkinsapi.Jenkins(self.jenkins_url) jenkins.update_job(job_id, f.read()) - def cmd_generate_jobs(self, args): - '''Generate jobs based on JSON format job specification file.''' + def cmd_run_jobs(self, args): + '''Update Jenkmins with jobs based specification, then run them.''' self.settings.require('jenkins-host') + if len(args) == 0: + return + if len(args) > 1: + raise cliapp.AppException('Can only handle one file') jenkins = simplejenkinsapi.Jenkins(self.jenkins_url) job_generator = JobGenerator(self.settings['pretend-jobs'], self.settings['pbuilder-max-age'], self.artifacts_url, self.settings['jenkins-host']) - created_job_ids = set() - for filename in args: - with open(filename) as f: - try: - config = json.load(f) - except ValueError, e: - raise cliapp.AppException('%s: %s' % (filename, str(e))) - for job_id, config_xml in job_generator.generate(config): - logging.debug('job_id = %s' % job_id) - logging.debug('config_xml:\n%s' % config_xml) - if job_id in jenkins.list_jobs(): - jenkins.update_job(job_id, config_xml) - else: - jenkins.create_job(job_id, config_xml) - created_job_ids.add(job_id) + + with open(args[0]) as f: + try: + config = json.load(f) + except ValueError, e: + raise cliapp.AppException('%s: %s' % (filename, str(e))) + + def make_it_so(job_id, config_xml): + if job_id in jenkins.list_jobs(): + jenkins.update_job(job_id, config_xml) + else: + jenkins.create_job(job_id, config_xml) + + job_ids = set() + for job_id, config_xml in job_generator.generate_setup_jobs(config): + make_it_so(job_id, config_xml) + job_ids.add(job_id) + for project in simplejenkinsapi.order(config['projects']): + pairs = job_generator.generate_project(config, project) + for job_id, config_xml in pairs: + make_it_so(job_id, config_xml) + job_ids.add(job_id) + for job_id in jenkins.list_jobs(): - if job_id not in created_job_ids: + if job_id not in job_ids: jenkins.delete_job(job_id) |