def build_project(gerrit_info, dry_run, lunch_target=None):
    project_to_jenkins_map = {
        "platform/bionic": "bionic-presubmit",
        "platform/build": "bionic-presubmit",
        "platform/external/jemalloc": "bionic-presubmit",
        "platform/external/libcxx": "bionic-presubmit",
        "platform/external/libcxxabi": "bionic-presubmit",
        "platform/external/compiler-rt": "bionic-presubmit",
    }

    username = config.jenkins_credentials["username"]
    password = config.jenkins_credentials["password"]
    jenkins_url = config.jenkins_url
    jenkins = jenkinsapi.api.Jenkins(jenkins_url, username, password)

    project = gerrit_info["Project"]
    change_id = gerrit_info["Change-Id"]
    if project in project_to_jenkins_map:
        build = project_to_jenkins_map[project]
    else:
        build = "bionic-presubmit"

    if build in jenkins:
        project_path = "/".join(project.split("/")[1:])
        if not project_path:
            raise RuntimeError("bogus project: {}".format(project))
        if project_path.startswith("platform/"):
            print "{}({}): {} => {}".format(termcolor.colored("ERROR", "red"), "project", project, project_path)
            return False
        try:
            ref = gerrit.ref_for_change(change_id)
        except gerrit.GerritError as ex:
            print "{}({}): {} {}".format(termcolor.colored("GERRIT-ERROR", "red"), ex.code, change_id, ex.url)
            return False
        params = {"REF": ref, "CHANGE_ID": change_id, "PROJECT": project_path}
        if lunch_target is not None:
            params["LUNCH_TARGET"] = lunch_target
        if not dry_run:
            _ = jenkins[build].invoke(build_params=params)
            # https://issues.jenkins-ci.org/browse/JENKINS-27256
            # url = job.get_build().baseurl
            url = "URL UNAVAILABLE"
        else:
            url = "DRY_RUN_URL"
        print "{}({}): {} => {} {} {}".format(
            termcolor.colored("BUILD", "green"), gerrit_info["MessageType"], project, build, url, change_id
        )
    else:
        print "{}({}): {} => {} {}".format(
            termcolor.colored("BUILD", "red"),
            gerrit_info["MessageType"],
            project,
            termcolor.colored(build, "red"),
            change_id,
        )
    return True
def build_project(gerrit_info, dry_run, lunch_target=None):
    project_to_jenkins_map = {
        'platform/bionic': 'bionic-presubmit',
        'platform/build': 'bionic-presubmit',
        'platform/external/jemalloc': 'bionic-presubmit',
        'platform/external/libcxx': 'bionic-presubmit',
        'platform/external/libcxxabi': 'bionic-presubmit',
        'platform/external/compiler-rt': 'bionic-presubmit',
    }

    username = config.jenkins_credentials['username']
    password = config.jenkins_credentials['password']
    jenkins_url = config.jenkins_url
    jenkins = jenkinsapi.api.Jenkins(jenkins_url, username, password)

    project = gerrit_info['Project']
    change_id = gerrit_info['Change-Id']
    if project in project_to_jenkins_map:
        build = project_to_jenkins_map[project]
    else:
        build = 'bionic-presubmit'

    if build in jenkins:
        project_path = '/'.join(project.split('/')[1:])
        if not project_path:
            raise RuntimeError('bogus project: {}'.format(project))
        if project_path.startswith('platform/'):
            print '{}({}): {} => {}'.format(termcolor.colored('ERROR', 'red'),
                                            'project', project, project_path)
            return False
        try:
            ref = gerrit.ref_for_change(change_id)
        except gerrit.GerritError as ex:
            print '{}({}): {} {}'.format(
                termcolor.colored('GERRIT-ERROR', 'red'), ex.code, change_id,
                ex.url)
            return False
        params = {'REF': ref, 'CHANGE_ID': change_id, 'PROJECT': project_path}
        if lunch_target is not None:
            params['LUNCH_TARGET'] = lunch_target
        if not dry_run:
            _ = jenkins[build].invoke(build_params=params)
            # https://issues.jenkins-ci.org/browse/JENKINS-27256
            # url = job.get_build().baseurl
            url = 'URL UNAVAILABLE'
        else:
            url = 'DRY_RUN_URL'
        print '{}({}): {} => {} {} {}'.format(
            termcolor.colored('BUILD', 'green'), gerrit_info['MessageType'],
            project, build, url, change_id)
    else:
        print '{}({}): {} => {} {}'.format(termcolor.colored('BUILD', 'red'),
                                           gerrit_info['MessageType'], project,
                                           termcolor.colored(build,
                                                             'red'), change_id)
    return True
def build_project(gerrit_info, dry_run, lunch_target=None):
    project_to_jenkins_map = {
        'platform/bionic': 'bionic-presubmit',
        'platform/build': 'bionic-presubmit',
        'platform/external/jemalloc': 'bionic-presubmit',
        'platform/external/libcxx': 'bionic-presubmit',
        'platform/external/libcxxabi': 'bionic-presubmit',
        'platform/external/compiler-rt': 'bionic-presubmit',
    }

    username = config.jenkins_credentials['username']
    password = config.jenkins_credentials['password']
    jenkins_url = config.jenkins_url
    jenkins = jenkinsapi.api.Jenkins(jenkins_url, username, password)

    project = gerrit_info['Project']
    change_id = gerrit_info['Change-Id']
    if project in project_to_jenkins_map:
        build = project_to_jenkins_map[project]
    else:
        build = 'bionic-presubmit'

    if build in jenkins:
        project_path = '/'.join(project.split('/')[1:])
        if not project_path:
            raise RuntimeError('bogus project: {}'.format(project))
        if project_path.startswith('platform/'):
            raise RuntimeError('Bad project mapping: {} => {}'.format(
                project, project_path))
        ref = gerrit.ref_for_change(change_id)
        params = {
            'REF': ref,
            'CHANGE_ID': change_id,
            'PROJECT': project_path
        }
        if lunch_target is not None:
            params['LUNCH_TARGET'] = lunch_target
        if not dry_run:
            _ = jenkins[build].invoke(build_params=params)
            # https://issues.jenkins-ci.org/browse/JENKINS-27256
            # url = job.get_build().baseurl
            url = 'URL UNAVAILABLE'
        else:
            url = 'DRY_RUN_URL'
        logging.info('Building: %s => %s %s %s', project, build, url,
                     change_id)
    else:
        logging.error('Unknown build: %s => %s %s', project, build, change_id)
    return True
Beispiel #4
0
def build_project(gerrit_info, dry_run, lunch_target=None):
    project_to_jenkins_map = {
        "platform/bionic": "bionic-presubmit",
        "platform/build": "bionic-presubmit",
        "platform/external/jemalloc": "bionic-presubmit",
        "platform/external/libcxx": "bionic-presubmit",
        "platform/external/libcxxabi": "bionic-presubmit",
        "platform/external/compiler-rt": "bionic-presubmit",
    }

    username = config.jenkins_credentials["username"]
    password = config.jenkins_credentials["password"]
    jenkins_url = config.jenkins_url
    jenkins = jenkinsapi.api.Jenkins(jenkins_url, username, password)

    project = gerrit_info["Project"]
    change_id = gerrit_info["Change-Id"]
    if project in project_to_jenkins_map:
        build = project_to_jenkins_map[project]
    else:
        build = "bionic-presubmit"

    if build in jenkins:
        project_path = "/".join(project.split("/")[1:])
        if not project_path:
            raise RuntimeError("bogus project: {}".format(project))
        if project_path.startswith("platform/"):
            raise RuntimeError("Bad project mapping: {} => {}".format(project, project_path))
        ref = gerrit.ref_for_change(change_id)
        params = {"REF": ref, "CHANGE_ID": change_id, "PROJECT": project_path}
        if lunch_target is not None:
            params["LUNCH_TARGET"] = lunch_target
        if not dry_run:
            _ = jenkins[build].invoke(build_params=params)
            # https://issues.jenkins-ci.org/browse/JENKINS-27256
            # url = job.get_build().baseurl
            url = "URL UNAVAILABLE"
        else:
            url = "DRY_RUN_URL"
        logging.info("Building: %s => %s %s %s", project, build, url, change_id)
    else:
        logging.error("Unknown build: %s => %s %s", project, build, change_id)
    return True