コード例 #1
0
def get_sub_builds(build_number,
                   job_name=JENKINS.get('job_name'),
                   jenkins_url=JENKINS.get('url')):
    """ Gather all sub build info into subbuild list

    :param build_number: int - Jenkins build number
    :param job_name: str - Jenkins job_name
    :param jenkins_url: str - Jenkins http url
    :return: sub_builds: list of dicts or None otherwise
             {build_info, test_data, failure_reasons}
             where:
             build_info(sub build specific info got from Jenkins)-dict
             test_data(test data per one sub build)-dict
             failure_reasons(failures per one sub build)-list
    """

    runner_build = Build(job_name, build_number)
    parent_build_info = runner_build.get_build_data(depth=0)
    sub_builds = None
    if parent_build_info:
        sub_builds = parent_build_info.get('subBuilds')
    if sub_builds:
        for i in sub_builds:
            test_data = get_build_test_data(i.get('buildNumber'),
                                            i.get('jobName'), jenkins_url)
            if test_data:
                i.update({'test_data': test_data})
                i.update({'description': test_data.get('job_description')})
                i.update(
                    {'failure_reasons': get_build_failure_reasons(test_data)})
    return sub_builds, parent_build_info
コード例 #2
0
def get_sub_builds(build_number, job_name=JENKINS.get('job_name'),
                   jenkins_url=JENKINS.get('url')):
    """ Gather all sub build info into subbuild list

    :param build_number: int - Jenkins build number
    :param job_name: str - Jenkins job_name
    :param jenkins_url: str - Jenkins http url
    :return: sub_builds: list of dicts or None otherwise
             {build_info, test_data, failure_reasons}
             where:
             build_info(sub build specific info got from Jenkins)-dict
             test_data(test data per one sub build)-dict
             failure_reasons(failures per one sub build)-list
    """

    runner_build = Build(job_name, build_number)
    parent_build_info = runner_build.get_build_data(depth=0)
    sub_builds = None
    if parent_build_info:
        sub_builds = parent_build_info.get('subBuilds')
    if sub_builds:
        for i in sub_builds:
            test_data = get_build_test_data(i.get('buildNumber'),
                                            i.get('jobName'),
                                            jenkins_url)
            if test_data:
                i.update({'test_data': test_data})
                i.update({'description': test_data.get('job_description')})
                i.update({'failure_reasons':
                          get_build_failure_reasons(test_data)})
    return sub_builds, parent_build_info
コード例 #3
0
def get_build_test_data(build_number, job_name,
                        jenkins_url=JENKINS.get('url')):
    """ Get build test data from Jenkins from nosetests.xml

    :param build_number: int - Jenkins build number
    :param job_name: str - Jenkins job_name
    :param jenkins_url: str - Jenkins http url
    :return: test_data: dict - build info or None otherwise
    """

    test_data = None
    logger.info('Getting subbuild {} {}'.format(job_name, build_number))
    runner_build = Build(job_name, build_number)
    buildinfo = runner_build.get_build_data(depth=0)
    if not buildinfo:
        logger.error('Getting subbuilds info is failed. '
                     'Job={} Build={}'.format(job_name, build_number))
        return test_data
    try:
        artifact_paths = [
            v for i in buildinfo.get('artifacts') for k, v in i.items()
            if k == 'relativePath'
            and v == JENKINS.get('xml_testresult_file_name')
        ][0]
        artifact_url = "/".join(
            [jenkins_url, 'job', job_name,
             str(build_number)])
        xdata = get_build_artifact(artifact_url, artifact_paths)
        test_data = xmltodict.parse(xdata, xml_attribs=True)
        test_data.update({
            'build_number': build_number,
            'job_name': job_name,
            'job_url': buildinfo.get('url'),
            'job_description': buildinfo.get('description'),
            'job_status': buildinfo.get('result')
        })
    except:
        test_data = None
    return test_data
コード例 #4
0
def get_build_test_data(build_number, job_name,
                        jenkins_url=JENKINS.get('url')):
    """ Get build test data from Jenkins from nosetests.xml

    :param build_number: int - Jenkins build number
    :param job_name: str - Jenkins job_name
    :param jenkins_url: str - Jenkins http url
    :return: test_data: dict - build info or None otherwise
    """

    test_data = None
    logger.info('Getting subbuild {} {}'.format(job_name,
                                                build_number))
    runner_build = Build(job_name, build_number)
    buildinfo = runner_build.get_build_data(depth=0)
    if not buildinfo:
        logger.error('Getting subbuilds info is failed. '
                     'Job={} Build={}'.format(job_name, build_number))
        return test_data
    try:
        artifact_paths = [v for i in buildinfo.get('artifacts')
                          for k, v in i.items() if k == 'relativePath' and
                          v == JENKINS.get('xml_testresult_file_name')][0]
        artifact_url = "/".join([jenkins_url, 'job', job_name,
                                 str(build_number)])
        xdata = get_build_artifact(artifact_url, artifact_paths)
        test_data = xmltodict.parse(xdata, xml_attribs=True)
        test_data.update({'build_number': build_number,
                          'job_name': job_name,
                          'job_url': buildinfo.get('url'),
                          'job_description':
                              buildinfo.get('description'),
                          'job_status': buildinfo.get('result')})
    except:
        test_data = None
    return test_data