Esempio n. 1
0
    def test_postprocess_build(self):
        """
        postprocess_build should trigger the importing of the build's artifacts,
        and then schedule any other post-build tasks.
        """
        job = JobFactory.create()
        build = BuildFactory.create(job=job)
        with mock.patch("jenkins.helpers.chain") as chain_mock:
            postprocess_build(build)

        chain_mock.assert_called_once_with(import_build_for_job.s(build.pk))
        chain_mock.return_value.apply_async.assert_called_once()
Esempio n. 2
0
    def test_postprocess_build(self):
        """
        postprocess_build should trigger the importing of the build's artifacts,
        and then schedule any other post-build tasks.
        """
        job = JobFactory.create()
        build = BuildFactory.create(job=job)
        with mock.patch("jenkins.helpers.chain") as chain_mock:
             postprocess_build(build)

        chain_mock.assert_called_once_with(
            import_build_for_job.s(build.pk))
        chain_mock.return_value.apply_async.assert_called_once()
Esempio n. 3
0
    def test_postprocess_build_with_additional_postprocess_tasks(self):
        """
        If settings.POST_BUILD_TASKS has a list of additional tasks to be
        executed after a build completes, then we should chain them after we've
        imported the artifacts for the build.
        """
        job = JobFactory.create()
        build = BuildFactory.create(job=job)
        with mock.patch("jenkins.helpers.chain") as chain_mock:
            postprocess_build(build)

        chain_mock.assert_called_once_with(import_build_for_job.s(build.pk),
                                           postbuild_testing_hook.s())
        chain_mock.return_value.apply_async.assert_called_once()
Esempio n. 4
0
    def post(self, request, *args, **kwargs):
        """
        Handle incoming Jenkins notifications.
        """
        server = self.get_server(request)
        if not server:
            return HttpResponse(status=412)
        notification = json.loads(request.body)

        try:
            job = server.job_set.get(name=notification["name"])
        except Job.DoesNotExist:
            logging.warn("Notification for unknown job '%s'" %
                         notification["name"])
            return HttpResponse(status=412)

        build_id = ""
        build_number = notification["build"]["number"]

        # Translate the build phase name, as we may be running with an older
        # version of the Notification plugin
        build_phase = Build.translate_build_phase(
            notification["build"]["phase"])

        if "parameters" in notification["build"]:
            build_id = notification["build"]["parameters"].get("BUILD_ID")

        if Build.STARTED == build_phase:
            job.build_set.create(number=build_number,
                                 build_id=build_id,
                                 phase=build_phase)
        elif Build.FINALIZED == build_phase:
            build_status = notification["build"]["status"]
            build_url = notification["build"]["url"]
            try:
                existing_build = job.build_set.get(number=build_number)
            except Build.DoesNotExist:
                existing_build = job.build_set.create(number=build_number,
                                                      build_id=build_id,
                                                      phase=build_phase,
                                                      status=build_status,
                                                      url=build_url)
            else:
                existing_build.status = build_status
                existing_build.phase = build_phase
                existing_build.url = build_url
                existing_build.save()
            postprocess_build(existing_build)

        return HttpResponse(status=200)
Esempio n. 5
0
    def test_postprocess_build_with_additional_postprocess_tasks(self):
        """
        If settings.POST_BUILD_TASKS has a list of additional tasks to be
        executed after a build completes, then we should chain them after we've
        imported the artifacts for the build.
        """
        job = JobFactory.create()
        build = BuildFactory.create(job=job)
        with mock.patch("jenkins.helpers.chain") as chain_mock:
            postprocess_build(build)

        chain_mock.assert_called_once_with(
            import_build_for_job.s(build.pk),
            postbuild_testing_hook.s())
        chain_mock.return_value.apply_async.assert_called_once()
Esempio n. 6
0
    def post(self, request, *args, **kwargs):
        """
        Handle incoming Jenkins notifications.
        """
        server = self.get_server(request)
        if not server:
            return HttpResponse(status=412)
        notification = json.loads(request.body)

        try:
            job = server.job_set.get(name=notification["name"])
        except Job.DoesNotExist:
            logging.warn(
                "Notification for unknown job '%s'" % notification["name"])
            return HttpResponse(status=412)

        build_id = ""
        build_number = notification["build"]["number"]

        # Translate the build phase name, as we may be running with an older
        # version of the Notification plugin
        build_phase = Build.translate_build_phase(notification["build"]["phase"])

        if "parameters" in notification["build"]:
            build_id = notification["build"]["parameters"].get("BUILD_ID")

        if Build.STARTED == build_phase:
            job.build_set.create(
                number=build_number, build_id=build_id, phase=build_phase)
        elif Build.FINALIZED == build_phase:
            build_status = notification["build"]["status"]
            build_url = notification["build"]["url"]
            try:
                existing_build = job.build_set.get(number=build_number)
            except Build.DoesNotExist:
                existing_build = job.build_set.create(
                    number=build_number, build_id=build_id, phase=build_phase,
                    status=build_status, url=build_url)
            else:
                existing_build.status = build_status
                existing_build.phase = build_phase
                existing_build.url = build_url
                existing_build.save()
            postprocess_build(existing_build)

        return HttpResponse(status=200)