Google Cloud Build V1 Client - Class CloudBuildClient (0.12.0)

Reference documentation and code samples for the Google Cloud Build V1 Client class CloudBuildClient.

Service Description: Creates and manages builds on Google Cloud Platform.

The main concept used by this API is a Build, which describes the location of the source to build, how to build the source, and where to store the built artifacts, if any.

A user can list previously-requested builds or get builds by their ID to determine the status of the build.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:

$cloudBuildClient = new CloudBuildClient();
try {
    $name = 'name';
    $operationResponse = $cloudBuildClient->approveBuild($name);
    $operationResponse->pollUntilComplete();
    if ($operationResponse->operationSucceeded()) {
        $result = $operationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $operationResponse->getError();
        // handleError($error)
    }
    // Alternatively:
    // start the operation, keep the operation name, and resume later
    $operationResponse = $cloudBuildClient->approveBuild($name);
    $operationName = $operationResponse->getName();
    // ... do other work
    $newOperationResponse = $cloudBuildClient->resumeOperation($operationName, 'approveBuild');
    while (!$newOperationResponse->isDone()) {
        // ... do other work
        $newOperationResponse->reload();
    }
    if ($newOperationResponse->operationSucceeded()) {
        $result = $newOperationResponse->getResult();
        // doSomethingWith($result)
    } else {
        $error = $newOperationResponse->getError();
        // handleError($error)
    }
} finally {
    $cloudBuildClient->close();
}

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Cloud \ Build \ V1

Methods

__construct

Constructor.

Parameters
NameDescription
options array

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials string|array|FetchAuthTokenInterface|CredentialsWrapper

The credentials to be used by the client to authorize API calls. This option accepts either a path to a credentials file, or a decoded credentials file as a PHP array. Advanced usage: In addition, this option can also accept a pre-constructed Google\Auth\FetchAuthTokenInterface object or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored.

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|TransportInterface

The transport used for executing network requests. May be either the string rest or grpc. Defaults to grpc if gRPC support is detected on the system. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'grpc' => [...], 'rest' => [...], ]; See the Google\ApiCore\Transport\GrpcTransport::build() and Google\ApiCore\Transport\RestTransport::build() methods for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

approveBuild

Approves or rejects a pending build.

If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call.

If rejected, the returned LRO will be immediately done.

Parameters
NameDescription
name string

Required. Name of the target build. For example: "projects/{$project_id}/builds/{$build_id}"

optionalArgs array

Optional.

↳ approvalResult ApprovalResult

Approval decision and metadata.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Rpc\Status;

/**
 * @param string $name Name of the target build.
 *                     For example: "projects/{$project_id}/builds/{$build_id}"
 */
function approve_build_sample(string $name): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->approveBuild($name);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Build $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $name = '[NAME]';

    approve_build_sample($name);
}

cancelBuild

Cancels a build in progress.

Parameters
NameDescription
projectId string

Required. ID of the project.

id string

Required. ID of the build.

optionalArgs array

Optional.

↳ name string

The name of the Build to cancel. Format: projects/{project}/locations/{location}/builds/{build}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\Build
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project.
 * @param string $id        ID of the build.
 */
function cancel_build_sample(string $projectId, string $id): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var Build $response */
        $response = $cloudBuildClient->cancelBuild($projectId, $id);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $id = '[ID]';

    cancel_build_sample($projectId, $id);
}

createBuild

Starts a build with the specified configuration.

This method returns a long-running Operation, which includes the build ID. Pass the build ID to GetBuild to determine the build status (such as SUCCESS or FAILURE).

Parameters
NameDescription
projectId string

Required. ID of the project.

build Google\Cloud\Build\V1\Build

Required. Build resource to create.

optionalArgs array

Optional.

↳ parent string

The parent resource where this build will be created. Format: projects/{project}/locations/{location}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Rpc\Status;

/**
 * @param string $projectId ID of the project.
 */
function create_build_sample(string $projectId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $build = new Build();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->createBuild($projectId, $build);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Build $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';

    create_build_sample($projectId);
}

createBuildTrigger

Creates a new BuildTrigger.

This API is experimental.

Parameters
NameDescription
projectId string

Required. ID of the project for which to configure automatic builds.

trigger Google\Cloud\Build\V1\BuildTrigger

Required. BuildTrigger to create.

optionalArgs array

Optional.

↳ parent string

The parent resource where this trigger will be created. Format: projects/{project}/locations/{location}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\BuildTrigger
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\BuildTrigger;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project for which to configure automatic builds.
 */
function create_build_trigger_sample(string $projectId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $trigger = new BuildTrigger();

    // Call the API and handle any network failures.
    try {
        /** @var BuildTrigger $response */
        $response = $cloudBuildClient->createBuildTrigger($projectId, $trigger);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';

    create_build_trigger_sample($projectId);
}

createWorkerPool

Creates a WorkerPool.

Parameters
NameDescription
parent string

Required. The parent resource where this worker pool will be created. Format: projects/{project}/locations/{location}.

workerPool Google\Cloud\Build\V1\WorkerPool

Required. WorkerPool resource to create.

workerPoolId string

Required. Immutable. The ID to use for the WorkerPool, which will become the final component of the resource name.

This value should be 1-63 characters, and valid characters are /[a-z][0-9]-/.

optionalArgs array

Optional.

↳ validateOnly bool

If set, validate the request and preview the response, but do not actually post it.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Cloud\Build\V1\WorkerPool;
use Google\Rpc\Status;

/**
 * @param string $formattedParent The parent resource where this worker pool will be created.
 *                                Format: `projects/{project}/locations/{location}`. Please see
 *                                {@see CloudBuildClient::locationName()} for help formatting this field.
 * @param string $workerPoolId    Immutable. The ID to use for the `WorkerPool`, which will become
 *                                the final component of the resource name.
 *
 *                                This value should be 1-63 characters, and valid characters
 *                                are /[a-z][0-9]-/.
 */
function create_worker_pool_sample(string $formattedParent, string $workerPoolId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $workerPool = new WorkerPool();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->createWorkerPool($formattedParent, $workerPool, $workerPoolId);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var WorkerPool $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CloudBuildClient::locationName('[PROJECT]', '[LOCATION]');
    $workerPoolId = '[WORKER_POOL_ID]';

    create_worker_pool_sample($formattedParent, $workerPoolId);
}

deleteBuildTrigger

Deletes a BuildTrigger by its project ID and trigger ID.

This API is experimental.

Parameters
NameDescription
projectId string

Required. ID of the project that owns the trigger.

triggerId string

Required. ID of the BuildTrigger to delete.

optionalArgs array

Optional.

↳ name string

The name of the Trigger to delete. Format: projects/{project}/locations/{location}/triggers/{trigger}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project that owns the trigger.
 * @param string $triggerId ID of the `BuildTrigger` to delete.
 */
function delete_build_trigger_sample(string $projectId, string $triggerId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        $cloudBuildClient->deleteBuildTrigger($projectId, $triggerId);
        printf('Call completed successfully.' . PHP_EOL);
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $triggerId = '[TRIGGER_ID]';

    delete_build_trigger_sample($projectId, $triggerId);
}

deleteWorkerPool

Deletes a WorkerPool.

Parameters
NameDescription
name string

Required. The name of the WorkerPool to delete. Format: projects/{project}/locations/{location}/workerPools/{workerPool}.

optionalArgs array

Optional.

↳ etag string

Optional. If provided, it must match the server's etag on the workerpool for the request to be processed.

↳ allowMissing bool

If set to true, and the WorkerPool is not found, the request will succeed but no action will be taken on the server.

↳ validateOnly bool

If set, validate the request and preview the response, but do not actually post it.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Rpc\Status;

/**
 * @param string $formattedName The name of the `WorkerPool` to delete.
 *                              Format:
 *                              `projects/{project}/locations/{location}/workerPools/{workerPool}`. Please see
 *                              {@see CloudBuildClient::workerPoolName()} for help formatting this field.
 */
function delete_worker_pool_sample(string $formattedName): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->deleteWorkerPool($formattedName);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            printf('Operation completed successfully.' . PHP_EOL);
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = CloudBuildClient::workerPoolName('[PROJECT]', '[LOCATION]', '[WORKER_POOL]');

    delete_worker_pool_sample($formattedName);
}

getBuild

Returns information about a previously requested build.

The Build that is returned includes its status (such as SUCCESS, FAILURE, or WORKING), and timing information.

Parameters
NameDescription
projectId string

Required. ID of the project.

id string

Required. ID of the build.

optionalArgs array

Optional.

↳ name string

The name of the Build to retrieve. Format: projects/{project}/locations/{location}/builds/{build}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\Build
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project.
 * @param string $id        ID of the build.
 */
function get_build_sample(string $projectId, string $id): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var Build $response */
        $response = $cloudBuildClient->getBuild($projectId, $id);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $id = '[ID]';

    get_build_sample($projectId, $id);
}

getBuildTrigger

Returns information about a BuildTrigger.

This API is experimental.

Parameters
NameDescription
projectId string

Required. ID of the project that owns the trigger.

triggerId string

Required. Identifier (id or name) of the BuildTrigger to get.

optionalArgs array

Optional.

↳ name string

The name of the Trigger to retrieve. Format: projects/{project}/locations/{location}/triggers/{trigger}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\BuildTrigger
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\BuildTrigger;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project that owns the trigger.
 * @param string $triggerId Identifier (`id` or `name`) of the `BuildTrigger` to get.
 */
function get_build_trigger_sample(string $projectId, string $triggerId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var BuildTrigger $response */
        $response = $cloudBuildClient->getBuildTrigger($projectId, $triggerId);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $triggerId = '[TRIGGER_ID]';

    get_build_trigger_sample($projectId, $triggerId);
}

getWorkerPool

Returns details of a WorkerPool.

Parameters
NameDescription
name string

Required. The name of the WorkerPool to retrieve. Format: projects/{project}/locations/{location}/workerPools/{workerPool}.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\WorkerPool
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Cloud\Build\V1\WorkerPool;

/**
 * @param string $formattedName The name of the `WorkerPool` to retrieve.
 *                              Format: `projects/{project}/locations/{location}/workerPools/{workerPool}`. Please see
 *                              {@see CloudBuildClient::workerPoolName()} for help formatting this field.
 */
function get_worker_pool_sample(string $formattedName): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var WorkerPool $response */
        $response = $cloudBuildClient->getWorkerPool($formattedName);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = CloudBuildClient::workerPoolName('[PROJECT]', '[LOCATION]', '[WORKER_POOL]');

    get_worker_pool_sample($formattedName);
}

listBuildTriggers

Lists existing BuildTriggers.

This API is experimental.

Parameters
NameDescription
projectId string

Required. ID of the project for which to list BuildTriggers.

optionalArgs array

Optional.

↳ parent string

The parent of the collection of Triggers. Format: projects/{project}/locations/{location}

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V1\BuildTrigger;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project for which to list BuildTriggers.
 */
function list_build_triggers_sample(string $projectId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $cloudBuildClient->listBuildTriggers($projectId);

        /** @var BuildTrigger $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';

    list_build_triggers_sample($projectId);
}

listBuilds

Lists previously requested builds.

Previously requested builds may still be in-progress, or may have finished successfully or unsuccessfully.

Parameters
NameDescription
projectId string

Required. ID of the project.

optionalArgs array

Optional.

↳ parent string

The parent of the collection of Builds. Format: projects/{project}/locations/{location}

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ filter string

The raw filter text to constrain the results.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project.
 */
function list_builds_sample(string $projectId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $cloudBuildClient->listBuilds($projectId);

        /** @var Build $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';

    list_builds_sample($projectId);
}

listWorkerPools

Lists WorkerPools.

Parameters
NameDescription
parent string

Required. The parent of the collection of WorkerPools. Format: projects/{project}/locations/{location}.

optionalArgs array

Optional.

↳ pageSize int

The maximum number of resources contained in the underlying API response. The API may return fewer values in a page, even if there are additional values to be retrieved.

↳ pageToken string

A page token is used to specify a page of values to be returned. If no page token is specified (the default), the first page of values will be returned. Any page token used here must have been generated by a previous call to the API.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\PagedListResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Cloud\Build\V1\WorkerPool;

/**
 * @param string $formattedParent The parent of the collection of `WorkerPools`.
 *                                Format: `projects/{project}/locations/{location}`. Please see
 *                                {@see CloudBuildClient::locationName()} for help formatting this field.
 */
function list_worker_pools_sample(string $formattedParent): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $cloudBuildClient->listWorkerPools($formattedParent);

        /** @var WorkerPool $element */
        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CloudBuildClient::locationName('[PROJECT]', '[LOCATION]');

    list_worker_pools_sample($formattedParent);
}

receiveTriggerWebhook

ReceiveTriggerWebhook [Experimental] is called when the API receives a webhook request targeted at a specific trigger.

Parameters
NameDescription
optionalArgs array

Optional.

↳ name string

The name of the ReceiveTriggerWebhook to retrieve. Format: projects/{project}/locations/{location}/triggers/{trigger}

↳ body HttpBody

HTTP request body.

↳ projectId string

Project in which the specified trigger lives

↳ trigger string

Name of the trigger to run the payload against

↳ secret string

Secret token used for authorization if an OAuth token isn't provided.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\ReceiveTriggerWebhookResponse
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Cloud\Build\V1\ReceiveTriggerWebhookResponse;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function receive_trigger_webhook_sample(): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var ReceiveTriggerWebhookResponse $response */
        $response = $cloudBuildClient->receiveTriggerWebhook();
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

retryBuild

Creates a new build based on the specified build.

This method creates a new build using the original build request, which may or may not result in an identical build.

For triggered builds:

  • Triggered builds resolve to a precise revision; therefore a retry of a triggered build will result in a build that uses the same revision.

For non-triggered builds that specify RepoSource:

  • If the original build built from the tip of a branch, the retried build will build from the tip of that branch, which may not be the same revision as the original build.
  • If the original build specified a commit sha or revision ID, the retried build will use the identical source.

For builds that specify StorageSource:

  • If the original build pulled source from Cloud Storage without specifying the generation of the object, the new build will use the current object, which may be different from the original build source.
  • If the original build pulled source from Cloud Storage and specified the generation of the object, the new build will attempt to use the same object, which may or may not be available depending on the bucket's lifecycle management settings.
Parameters
NameDescription
projectId string

Required. ID of the project.

id string

Required. Build ID of the original build.

optionalArgs array

Optional.

↳ name string

The name of the Build to retry. Format: projects/{project}/locations/{location}/builds/{build}

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Rpc\Status;

/**
 * @param string $projectId ID of the project.
 * @param string $id        Build ID of the original build.
 */
function retry_build_sample(string $projectId, string $id): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->retryBuild($projectId, $id);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Build $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $id = '[ID]';

    retry_build_sample($projectId, $id);
}

runBuildTrigger

Runs a BuildTrigger at a particular source revision.

To run a regional or global trigger, use the POST request that includes the location endpoint in the path (ex. v1/projects/{projectId}/locations/{region}/triggers/{triggerId}:run). The POST request that does not include the location endpoint in the path can only be used when running global triggers.

Parameters
NameDescription
projectId string

Required. ID of the project.

triggerId string

Required. ID of the trigger.

optionalArgs array

Optional.

↳ name string

The name of the Trigger to run. Format: projects/{project}/locations/{location}/triggers/{trigger}

↳ source RepoSource

Source to build against this trigger. Branch and tag names cannot consist of regular expressions.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\Build;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Rpc\Status;

/**
 * @param string $projectId ID of the project.
 * @param string $triggerId ID of the trigger.
 */
function run_build_trigger_sample(string $projectId, string $triggerId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->runBuildTrigger($projectId, $triggerId);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var Build $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $triggerId = '[TRIGGER_ID]';

    run_build_trigger_sample($projectId, $triggerId);
}

updateBuildTrigger

Updates a BuildTrigger by its project ID and trigger ID.

This API is experimental.

Parameters
NameDescription
projectId string

Required. ID of the project that owns the trigger.

triggerId string

Required. ID of the BuildTrigger to update.

trigger Google\Cloud\Build\V1\BuildTrigger

Required. BuildTrigger to update.

optionalArgs array

Optional.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\Cloud\Build\V1\BuildTrigger
Example
use Google\ApiCore\ApiException;
use Google\Cloud\Build\V1\BuildTrigger;
use Google\Cloud\Build\V1\CloudBuildClient;

/**
 * @param string $projectId ID of the project that owns the trigger.
 * @param string $triggerId ID of the `BuildTrigger` to update.
 */
function update_build_trigger_sample(string $projectId, string $triggerId): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $trigger = new BuildTrigger();

    // Call the API and handle any network failures.
    try {
        /** @var BuildTrigger $response */
        $response = $cloudBuildClient->updateBuildTrigger($projectId, $triggerId, $trigger);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $projectId = '[PROJECT_ID]';
    $triggerId = '[TRIGGER_ID]';

    update_build_trigger_sample($projectId, $triggerId);
}

updateWorkerPool

Updates a WorkerPool.

Parameters
NameDescription
workerPool Google\Cloud\Build\V1\WorkerPool

Required. The WorkerPool to update.

The name field is used to identify the WorkerPool to update. Format: projects/{project}/locations/{location}/workerPools/{workerPool}.

optionalArgs array

Optional.

↳ updateMask FieldMask

A mask specifying which fields in worker_pool to update.

↳ validateOnly bool

If set, validate the request and preview the response, but do not actually post it.

↳ retrySettings RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
TypeDescription
Google\ApiCore\OperationResponse
Example
use Google\ApiCore\ApiException;
use Google\ApiCore\OperationResponse;
use Google\Cloud\Build\V1\CloudBuildClient;
use Google\Cloud\Build\V1\WorkerPool;
use Google\Rpc\Status;

/**
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function update_worker_pool_sample(): void
{
    // Create a client.
    $cloudBuildClient = new CloudBuildClient();

    // Prepare any non-scalar elements to be passed along with the request.
    $workerPool = new WorkerPool();

    // Call the API and handle any network failures.
    try {
        /** @var OperationResponse $response */
        $response = $cloudBuildClient->updateWorkerPool($workerPool);
        $response->pollUntilComplete();

        if ($response->operationSucceeded()) {
            /** @var WorkerPool $result */
            $result = $response->getResult();
            printf('Operation successful with response data: %s' . PHP_EOL, $result->serializeToJsonString());
        } else {
            /** @var Status $error */
            $error = $response->getError();
            printf('Operation failed with error data: %s' . PHP_EOL, $error->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

getOperationsClient

Return an OperationsClient object with the same endpoint as $this.

Returns
TypeDescription
Google\ApiCore\LongRunning\OperationsClient

resumeOperation

Resume an existing long running operation that was previously started by a long running API method. If $methodName is not provided, or does not match a long running API method, then the operation can still be resumed, but the OperationResponse object will not deserialize the final response.

Parameters
NameDescription
operationName string

The name of the long running operation

methodName string

The name of the method used to start the operation

Returns
TypeDescription
Google\ApiCore\OperationResponse

static::buildName

Formats a string containing the fully-qualified path to represent a build resource.

Parameters
NameDescription
project string
build string
Returns
TypeDescription
stringThe formatted build resource.

static::buildTriggerName

Formats a string containing the fully-qualified path to represent a build_trigger resource.

Parameters
NameDescription
project string
trigger string
Returns
TypeDescription
stringThe formatted build_trigger resource.

static::cryptoKeyName

Formats a string containing the fully-qualified path to represent a crypto_key resource.

Parameters
NameDescription
project string
location string
keyring string
key string
Returns
TypeDescription
stringThe formatted crypto_key resource.

static::githubEnterpriseConfigName

Formats a string containing the fully-qualified path to represent a github_enterprise_config resource.

Parameters
NameDescription
project string
config string
Returns
TypeDescription
stringThe formatted github_enterprise_config resource.

static::locationName

Formats a string containing the fully-qualified path to represent a location resource.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
stringThe formatted location resource.

static::networkName

Formats a string containing the fully-qualified path to represent a network resource.

Parameters
NameDescription
project string
network string
Returns
TypeDescription
stringThe formatted network resource.

static::projectName

Formats a string containing the fully-qualified path to represent a project resource.

Parameter
NameDescription
project string
Returns
TypeDescription
stringThe formatted project resource.

static::projectBuildName

Formats a string containing the fully-qualified path to represent a project_build resource.

Parameters
NameDescription
project string
build string
Returns
TypeDescription
stringThe formatted project_build resource.

static::projectConfigName

Formats a string containing the fully-qualified path to represent a project_config resource.

Parameters
NameDescription
project string
config string
Returns
TypeDescription
stringThe formatted project_config resource.

static::projectLocationBuildName

Formats a string containing the fully-qualified path to represent a project_location_build resource.

Parameters
NameDescription
project string
location string
build string
Returns
TypeDescription
stringThe formatted project_location_build resource.

static::projectLocationConfigName

Formats a string containing the fully-qualified path to represent a project_location_config resource.

Parameters
NameDescription
project string
location string
config string
Returns
TypeDescription
stringThe formatted project_location_config resource.

static::projectLocationTriggerName

Formats a string containing the fully-qualified path to represent a project_location_trigger resource.

Parameters
NameDescription
project string
location string
trigger string
Returns
TypeDescription
stringThe formatted project_location_trigger resource.

static::projectTriggerName

Formats a string containing the fully-qualified path to represent a project_trigger resource.

Parameters
NameDescription
project string
trigger string
Returns
TypeDescription
stringThe formatted project_trigger resource.

static::repositoryName

Formats a string containing the fully-qualified path to represent a repository resource.

Parameters
NameDescription
project string
location string
connection string
repository string
Returns
TypeDescription
stringThe formatted repository resource.

static::secretVersionName

Formats a string containing the fully-qualified path to represent a secret_version resource.

Parameters
NameDescription
project string
secret string
version string
Returns
TypeDescription
stringThe formatted secret_version resource.

static::serviceAccountName

Formats a string containing the fully-qualified path to represent a service_account resource.

Parameters
NameDescription
project string
serviceAccount string
Returns
TypeDescription
stringThe formatted service_account resource.

static::subscriptionName

Formats a string containing the fully-qualified path to represent a subscription resource.

Parameters
NameDescription
project string
subscription string
Returns
TypeDescription
stringThe formatted subscription resource.

static::topicName

Formats a string containing the fully-qualified path to represent a topic resource.

Parameters
NameDescription
project string
topic string
Returns
TypeDescription
stringThe formatted topic resource.

static::workerPoolName

Formats a string containing the fully-qualified path to represent a worker_pool resource.

Parameters
NameDescription
project string
location string
workerPool string
Returns
TypeDescription
stringThe formatted worker_pool resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • build: projects/{project}/builds/{build}
  • buildTrigger: projects/{project}/triggers/{trigger}
  • cryptoKey: projects/{project}/locations/{location}/keyRings/{keyring}/cryptoKeys/{key}
  • githubEnterpriseConfig: projects/{project}/githubEnterpriseConfigs/{config}
  • location: projects/{project}/locations/{location}
  • network: projects/{project}/global/networks/{network}
  • project: projects/{project}
  • projectBuild: projects/{project}/builds/{build}
  • projectConfig: projects/{project}/githubEnterpriseConfigs/{config}
  • projectLocationBuild: projects/{project}/locations/{location}/builds/{build}
  • projectLocationConfig: projects/{project}/locations/{location}/githubEnterpriseConfigs/{config}
  • projectLocationTrigger: projects/{project}/locations/{location}/triggers/{trigger}
  • projectTrigger: projects/{project}/triggers/{trigger}
  • repository: projects/{project}/locations/{location}/connections/{connection}/repositories/{repository}
  • secretVersion: projects/{project}/secrets/{secret}/versions/{version}
  • serviceAccount: projects/{project}/serviceAccounts/{service_account}
  • subscription: projects/{project}/subscriptions/{subscription}
  • topic: projects/{project}/topics/{topic}
  • workerPool: projects/{project}/locations/{location}/workerPools/{worker_pool}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
NameDescription
formattedName string

The formatted name string

template string

Optional name of template to match

Returns
TypeDescription
arrayAn associative array from name component IDs to component values.

Constants

SERVICE_NAME

Value: 'google.devtools.cloudbuild.v1.CloudBuild'

The name of the service.

SERVICE_ADDRESS

Value: 'cloudbuild.googleapis.com'

The default address of the service.

DEFAULT_SERVICE_PORT

Value: 443

The default port of the service.

CODEGEN_NAME

Value: 'gapic'

The name of the code generator, to be included in the agent header.