Ejemplo n.º 1
0
 def create(self, name, pipeline_definition):
     try:
         pipeline = self.repository.create(name, pipeline_definition)
         PluginEvents.on_pipeline_created(pipeline)
         raise cherrypy.HTTPRedirect("/pipeline")
     except (ProjectNotFoundError, CyclicalPipelineError), err:
         pipelines = self.repository.get_all()
         return template.render(
             authenticated=self.authenticated(), pipelines=pipelines, pipeline=None, errors=[err.message]
         ) | HTMLFormFiller(data=locals())
Ejemplo n.º 2
0
 def update(self, project_id, name, build_script, scm_repository, monitor_changes=None, **data):
     project = self.repository.get(project_id)
     project.name = name
     project.build_script = build_script
     project.scm_repository = scm_repository
     project.monitor_changes = not monitor_changes is None
     self.repository.update(
         project, self.__process_tabs_for(data), file_locators=self.__process_file_locators_for(data)
     )
     PluginEvents.on_project_updated(project)
     raise cherrypy.HTTPRedirect("/")
Ejemplo n.º 3
0
 def create(self, name, build_script, scm_repository, monitor_changes=None, **data):
     project = self.repository.create(
         name=name,
         build_script=build_script,
         scm_repository=scm_repository,
         monitor_changes=not monitor_changes is None,
         tabs=self.__process_tabs_for(data),
         file_locators=self.__process_file_locators_for(data),
     )
     PluginEvents.on_project_created(project)
     raise cherrypy.HTTPRedirect("/")
Ejemplo n.º 4
0
    def build_project(self, project_id):
        ctx = SkinkContext.current()
        
        log = ["Build started at %s" % datetime.now()]

        status = BuildService.Failure
        scm_status = ScmResult.Failed
        project = self.repository.get(project_id)
        PluginEvents.on_before_build(project)
        ctx.projects_being_built.append(project_id)
        last_build_number = project.get_last_build_number()

        build = Build()
        build.date = datetime.now()
        build.status = status
        build.scm_status = scm_status
        build.log = ""
        build.project = project
        
        scm_creation_result = self.scm.create_or_update(project)
        build.scm_status = scm_creation_result.status
        if scm_creation_result.status == ScmResult.Failed:
            log.append(scm_creation_result.log)
            status = BuildService.Failure
        else:
            log.append("Downloaded code from %s (%s)" % (project.scm_repository, scm_creation_result.status))
            
            execute_result = self.executer.execute(project.build_script, 
                                                   scm_creation_result.repository_path, 
                                                   timeout=ctx.build_timeout)

            log.append("Executed %s" % project.build_script)
            log.append("Exit Code: %s" % execute_result.exit_code)
            log.append("Run Log:")
            log.append(execute_result.run_log)

            status = execute_result.exit_code == 0 and BuildService.Success or BuildService.Failure

        for command in project.tabs:
            build_tab = BuildTab(name=command.name, command=command.command, content_type=command.content_type, build=build)
            result = self.executer.execute(command.command, scm_creation_result.repository_path)
            build_tab.log = result.run_log

        for file_locator in project.file_locators:
            file_locator_path = join(self.base_path, project.name, file_locator.locator)
            print "Finding files for locator %s" % file_locator_path
            files = glob.glob(file_locator_path)
            print "%d files found" % len(files)
            for f in files:
                print "Adding file %s" % f
                filename = split(f)[-1]
                stream = open(f, 'rb')
                content = stream.read()
                stream.close()
                build_file = BuildFile(name=filename, original_path=f, content=content, build=build)

        build.number = last_build_number + 1
        build.status = status
        build.log = "\n".join(log)
        build.commit_number = force_unicode(scm_creation_result.last_commit["commit_number"])
        build.commit_author = force_unicode(scm_creation_result.last_commit["author"])
        build.commit_committer = force_unicode(scm_creation_result.last_commit["committer"])
        build.commit_author_date = scm_creation_result.last_commit["author_date"]
        build.commit_committer_date = scm_creation_result.last_commit["committer_date"]
        build.commit_text = force_unicode(scm_creation_result.last_commit["subject"])

        self.repository.update(project, project.tabs, [locator.locator for locator in project.file_locators])
        
        ctx.projects_being_built.remove(project_id)

        if (build.status == BuildService.Success):
            PluginEvents.on_build_successful(project, build)
            self.process_pipelines_for(project)
        else:
            PluginEvents.on_build_failed(project, build)
        
        return build
Ejemplo n.º 5
0
 def delete(self, pipeline_id):
     pipeline = self.repository.get(pipeline_id)
     self.repository.delete(pipeline_id)
     PluginEvents.on_pipeline_deleted(pipeline)
     raise cherrypy.HTTPRedirect("/pipeline")
Ejemplo n.º 6
0
 def delete(self, project_id):
     project = self.repository.get(project_id)
     self.repository.delete(project_id)
     self.build_service.delete_scm_repository(project)
     PluginEvents.on_project_deleted(project)
     raise cherrypy.HTTPRedirect("/")