Ejemplo n.º 1
0
def TriggerV2Build(builder,
                   gitiles_commit,
                   properties,
                   tags=None,
                   dimensions=None):
    """Triggers a build using buildbucket v2 API.

  Args:
    builder (build_pb2.BuilderID): Information about the builder the
      build runs on.
    gitiles_commit (common_pb2.GitilesCommit): Input commit the build runs.
    properties (dict): Input properties of the build.
    tags (list of dict): Tags for the build. In the format:
      [
        {
          'key': 'tag-key',
          'value': 'tag-value'
        },
        ...
      ]
    dimensions (list of dict): configured dimensions of the build. Format:
      [
        {
          'key': 'dimension-key',
          'value': 'dimension-value'
        },
        ...
      ]
  """
    request = ScheduleBuildRequest(builder=builder,
                                   gitiles_commit=gitiles_commit,
                                   tags=tags or [],
                                   dimensions=dimensions or [])
    request.properties.update(properties)

    status_code, content, response_headers = FinditHttpClient().Post(
        _BUILDBUCKET_V2_SCHEDULE_BUILD_ENDPOINT,
        request.SerializeToString(),
        headers={'Content-Type': 'application/prpc; encoding=binary'})

    if status_code == 200 and response_headers.get(
            'X-Prpc-Grpc-Code') == GRPC_OK:
        result = Build()
        result.ParseFromString(content)
        return result

    logging.warning('Unexpected status_code: %d and prpc code: %s',
                    status_code, response_headers.get('X-Prpc-Grpc-Code'))
    return None
Ejemplo n.º 2
0
def GetV2BuildByBuilderAndBuildNumber(project,
                                      bucket,
                                      builder_name,
                                      build_number,
                                      fields=None):
    """Get a buildbucket build from the v2 API by build info."""
    builder = BuilderID(project=project, bucket=bucket, builder=builder_name)
    request = GetBuildRequest(builder=builder,
                              build_number=build_number,
                              fields=fields)
    status_code, content, response_headers = FinditHttpClient().Post(
        _BUILDBUCKET_V2_GET_BUILD_ENDPOINT,
        request.SerializeToString(),
        headers={'Content-Type': 'application/prpc; encoding=binary'})
    if status_code == 200 and response_headers.get(
            'X-Prpc-Grpc-Code') == GRPC_OK:
        result = Build()
        result.ParseFromString(content)
        return result
    logging.warning('Unexpected prpc code: %s',
                    response_headers.get('X-Prpc-Grpc-Code'))
    return None
Ejemplo n.º 3
0
def GetV2Build(build_id, fields=None):
    """Get a buildbucket build from the v2 API.

  Args:
    build_id (str): Buildbucket id of the build to get.
    fields (google.protobuf.FieldMask): Mask for the paths to get, as not all
        fields are populated by default (such as steps).

  Returns:
    A buildbucket_proto.build_pb2.Build proto.
  """
    request = GetBuildRequest(id=int(build_id), fields=fields)
    status_code, content, response_headers = FinditHttpClient().Post(
        _BUILDBUCKET_V2_GET_BUILD_ENDPOINT,
        request.SerializeToString(),
        headers={'Content-Type': 'application/prpc; encoding=binary'})
    if status_code == 200 and response_headers.get(
            'X-Prpc-Grpc-Code') == GRPC_OK:
        result = Build()
        result.ParseFromString(content)
        return result
    logging.warning('Unexpected prpc code: %s',
                    response_headers.get('X-Prpc-Grpc-Code'))
    return None