def _handle_triggers(storage, run): if not run.complete or not run.trigger: return projdef = ProjectDefinition( yaml.safe_load(storage.get_project_definition(run.build))) rundef = json.loads(storage.get_run_definition(run)) secrets = rundef.get('secrets') params = rundef.get('env', {}) params['H_TRIGGER_URL'] = request.url run_trigger = projdef.get_trigger(run.trigger) try: for rt in run_trigger['runs']: if rt['name'] == run.name: if run.status == BuildStatus.PASSED: _create_triggers(projdef, storage, run.build, params, secrets, rt.get('triggers', []), run_trigger['type'], run.queue_priority) db.session.refresh(run.build) run.build.refresh_status() if run.build.complete: _handle_build_complete(projdef, storage, run.build, params, secrets, run_trigger) except ValueError as e: current_app.logger.exception( 'Caught integrity error and failed run: %d', run.id) run.set_status(BuildStatus.FAILED) content = storage.get_artifact_content(run, 'console.log') with storage.console_logfd(run, 'w') as f: f.write(content) f.write('\n\n== ERROR TRIGGERING RUN: %s\n' % e) storage.copy_log(run)
def _handle_triggers(storage, run): if not run.complete or not run.trigger: return projdef = ProjectDefinition( yaml.safe_load(storage.get_project_definition(run.build))) rundef = json.loads(storage.get_run_definition(run)) secrets = rundef.get("secrets") params = rundef.get("env", {}) params["H_TRIGGER_URL"] = request.url run_trigger = projdef.get_trigger(run.trigger) try: for rt in run_trigger["runs"]: if rt["name"] == run.name: if run.status == BuildStatus.PASSED: _create_triggers( projdef, storage, run.build, params, secrets, rt.get("triggers", []), run_trigger, run.queue_priority, ) db.session.refresh(run.build) run.build.refresh_status() if run.build.complete: _handle_build_complete(projdef, storage, run.build, params, secrets, run_trigger) except ValueError as e: current_app.logger.exception( "Caught integrity error and failed run: %d", run.id) run.set_status(BuildStatus.FAILED) content = storage.get_artifact_content(run, "console.log") with storage.console_logfd(run, "w") as f: f.write(content) f.write("\n\n== ERROR TRIGGERING RUN: %s\n" % e) storage.copy_log(run)