~qajenkinsbot/qa-dashboard/ci-production

« back to all changes in this revision

Viewing changes to util/jenkins_job.py

  • Committer: Canonical QA Jenkins Bot
  • Date: 2013-08-09 21:58:23 UTC
  • mfrom: (20.2.20 ci)
  • Revision ID: chris.johnston@canonical.com-20130809215823-svvl5y3o9qdvtoez
[Jenkins-10]

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
]
44
44
 
45
45
 
46
 
@transaction.autocommit
47
46
def create_jenkins_job_from_url(url,
48
47
                                update=False,
49
48
                                create_builds=True,
71
70
        params = {'name': extractor_job.name,
72
71
                  'url': url,
73
72
                  'buildable': extractor_job.buildable,
74
 
                  'in_queue': extractor_job.in_queue,
75
 
                  'last_build': extractor_job.last_build,
76
 
                  'last_completed_build': extractor_job.last_completed_build,
77
 
                  'last_failed_build': extractor_job.last_failed_build,
78
 
                  'last_successful_build': extractor_job.last_successful_build}
79
 
        jenkins_job = JenkinsJob.objects.create(**params)
 
73
                  'in_queue': extractor_job.in_queue}
 
74
        jenkins_job, created = JenkinsJob.objects.get_or_create(**params)
80
75
    except EnvironmentError, e:
81
 
        # No job found: this can happen when a project is defined in a stack but
82
 
        # the jobs have not yet been deployed
 
76
        # No job found on the server: this can happen when a project is
 
77
        # defined in a stack but the jobs have not yet been deployed.
83
78
        transaction.rollback()
84
79
        logger.debug(e)
85
80
        return None
86
 
    except IntegrityError, e:
87
 
        # uniqueness constraint violated
88
 
        transaction.rollback()
89
 
        logger.debug(e)
90
 
        jenkins_job = JenkinsJob.objects.get(name=extractor_job.name)
 
81
    if not created:
 
82
        # The job already exists in the database: this is normal even during
 
83
        # a fresh import due to the multiple build/job discovery paths.
91
84
        if update:
92
85
            logger.debug("Updating job from {}".format(url))
93
86
            jenkins_job.update(**params)