Exemplo n.º 1
0
def wait_on_builds(build_ids, credentials, cloud_project):
    """Waits on |builds|. Returns True if all builds succeed."""
    cloudbuild = cloud_build(
        'cloudbuild',
        'v1',
        credentials=credentials,
        cache_discovery=False,
        client_options=build_lib.US_CENTRAL_CLIENT_OPTIONS)
    cloudbuild_api = cloudbuild.projects().builds()  # pylint: disable=no-member

    wait_builds = build_ids.copy()
    build_results = {}
    while wait_builds:
        logging.info('Polling')
        for project, build_id in list(wait_builds.items()):
            if check_finished(build_id, project, cloudbuild_api, cloud_project,
                              build_results):
                del wait_builds[project]
            time.sleep(1)  # Avoid rate limiting.
        print(wait_builds)

    print('Printing results')
    print('Project, Statuses')
    for project, build_result in build_results.items():
        print(project, build_result)

    return all(build_results.items())
Exemplo n.º 2
0
def run_build(  # pylint: disable=too-many-arguments
    steps,
    credentials,
    cloud_project,
    timeout,
    body_overrides=None,
    tags=None,
    use_build_pool=True):
  """Runs the build."""

  build_body = get_build_body(steps,
                              timeout,
                              body_overrides,
                              tags,
                              use_build_pool=use_build_pool)

  cloudbuild = cloud_build('cloudbuild',
                           'v1',
                           credentials=credentials,
                           cache_discovery=False,
                           client_options=US_CENTRAL_CLIENT_OPTIONS)

  build_info = cloudbuild.projects().builds().create(projectId=cloud_project,
                                                     body=build_body).execute()

  build_id = build_info['metadata']['build']['id']

  logging.info('Build ID: %s', build_id)
  logging.info('Logs: %s', get_logs_url(build_id, cloud_project))
  logging.info('Cloud build page: %s', get_gcb_url(build_id, cloud_project))
  return build_id
Exemplo n.º 3
0
def run_build(oss_fuzz_project,
              build_steps,
              credentials,
              build_type,
              cloud_project='oss-fuzz'):
    """Run the build for given steps on cloud build. |build_steps| are the steps
  to run. |credentials| are are used to authenticate to GCB and build in
  |cloud_project|. |oss_fuzz_project| and |build_type| are used to tag the build
  in GCB so the build can be queried for debugging purposes."""
    options = {}
    if 'GCB_OPTIONS' in os.environ:
        options = yaml.safe_load(os.environ['GCB_OPTIONS'])
    else:
        options = DEFAULT_GCB_OPTIONS

    tags = [oss_fuzz_project + '-' + build_type, build_type, oss_fuzz_project]
    timeout_value = build_lib.BUILD_TIMEOUT
    # TODO (navidem): this is temporary until I fix shorter failing projects
    if build_type == 'introspector':
        timeout_value /= 4
    build_body = {
        'steps': build_steps,
        'timeout': str(timeout_value) + 's',
        'options': options,
        'logsBucket': GCB_LOGS_BUCKET,
        'tags': tags,
        'queueTtl': str(QUEUE_TTL_SECONDS) + 's',
    }

    cloudbuild = cloud_build('cloudbuild',
                             'v1',
                             credentials=credentials,
                             cache_discovery=False)
    build_info = cloudbuild.projects().builds().create(
        projectId=cloud_project, body=build_body).execute()
    build_id = build_info['metadata']['build']['id']

    logging.info('Build ID: %s', build_id)
    logging.info('Logs: %s', get_logs_url(build_id, cloud_project))
    logging.info('Cloud build page: %s', get_gcb_url(build_id, cloud_project))
    return build_id
Exemplo n.º 4
0
def run_build(  # pylint: disable=too-many-arguments
        steps,
        credentials,
        cloud_project,
        timeout,
        body_overrides=None,
        tags=None):
    """Runs the build."""
    if 'GCB_OPTIONS' in os.environ:
        options = yaml.safe_load(os.environ['GCB_OPTIONS'])
    else:
        options = DEFAULT_GCB_OPTIONS

    build_body = {
        'steps': steps,
        'timeout': str(timeout) + 's',
        'options': options,
    }
    if tags:
        build_body['tags'] = tags

    if body_overrides is None:
        body_overrides = {}
    for key, value in body_overrides.items():
        build_body[key] = value

    cloudbuild = cloud_build('cloudbuild',
                             'v1',
                             credentials=credentials,
                             cache_discovery=False)
    build_info = cloudbuild.projects().builds().create(
        projectId=cloud_project, body=build_body).execute()
    build_id = build_info['metadata']['build']['id']

    logging.info('Build ID: %s', build_id)
    logging.info('Logs: %s', get_logs_url(build_id, cloud_project))
    logging.info('Cloud build page: %s', get_gcb_url(build_id, cloud_project))
    return build_id