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 {
$projectId = 'project_id';
$id = 'id';
$response = $cloudBuildClient->cancelBuild($projectId, $id);
} 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.
Methods
buildName
Formats a string containing the fully-qualified path to represent a build resource.
project
string
build
string
string
buildTriggerName
Formats a string containing the fully-qualified path to represent a build_trigger resource.
project
string
trigger
string
string
locationName
Formats a string containing the fully-qualified path to represent a location resource.
project
string
location
string
string
projectName
Formats a string containing the fully-qualified path to represent a project resource.
project
string
string
projectBuildName
Formats a string containing the fully-qualified path to represent a project_build resource.
project
string
build
string
string
projectLocationBuildName
Formats a string containing the fully-qualified path to represent a project_location_build resource.
project
string
location
string
build
string
string
serviceAccountName
Formats a string containing the fully-qualified path to represent a service_account resource.
project
string
serviceAccount
string
string
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}
- location: projects/{project}/locations/{location}
- project: projects/{project}
- projectBuild: projects/{project}/builds/{build}
- projectLocationBuild: projects/{project}/locations/{location}/builds/{build}
- serviceAccount: projects/{project}/serviceAccounts/{service_account}
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.
formattedName
string
The formatted name string
template
string
Optional name of template to match
array
getOperationsClient
Return an OperationsClient object with the same endpoint as $this.
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.
operationName
string
The name of the long running operation
methodName
string
The name of the method used to start the operation
__construct
Constructor.
options
array
Optional. Options for configuring the service API wrapper.
↳ serviceAddress
string
Deprecated. This option will be removed in a future major release. Please utilize the $apiEndpoint
option instead.
↳ 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 $serviceAddress 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.
cancelBuild
Cancels a build in progress.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$id = 'id';
$response = $cloudBuildClient->cancelBuild($projectId, $id);
} finally {
$cloudBuildClient->close();
}
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
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
).
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$build = new Build();
$operationResponse = $cloudBuildClient->createBuild($projectId, $build);
$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->createBuild($projectId, $build);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudBuildClient->resumeOperation($operationName, 'createBuild');
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();
}
projectId
string
Required. ID of the project.
build
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
createBuildTrigger
Creates a new BuildTrigger
.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$trigger = new BuildTrigger();
$response = $cloudBuildClient->createBuildTrigger($projectId, $trigger);
} finally {
$cloudBuildClient->close();
}
projectId
string
Required. ID of the project for which to configure automatic builds.
trigger
optionalArgs
array
Optional.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
createWorkerPool
Creates a WorkerPool
to run the builds, and returns the new worker pool.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$response = $cloudBuildClient->createWorkerPool();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ parent
string
ID of the parent project.
↳ workerPool
WorkerPool
WorkerPool
resource to create.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
deleteBuildTrigger
Deletes a BuildTrigger
by its project ID and trigger ID.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$triggerId = 'trigger_id';
$cloudBuildClient->deleteBuildTrigger($projectId, $triggerId);
} finally {
$cloudBuildClient->close();
}
projectId
string
Required. ID of the project that owns the trigger.
triggerId
string
Required. ID of the BuildTrigger
to delete.
optionalArgs
array
Optional.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
deleteWorkerPool
Deletes a WorkerPool
by its project ID and WorkerPool name.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$cloudBuildClient->deleteWorkerPool();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ name
string
The field will contain name of the resource requested, for example: "projects/project-1/workerPools/workerpool-name"
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
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.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$id = 'id';
$response = $cloudBuildClient->getBuild($projectId, $id);
} finally {
$cloudBuildClient->close();
}
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
getBuildTrigger
Returns information about a BuildTrigger
.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$triggerId = 'trigger_id';
$response = $cloudBuildClient->getBuildTrigger($projectId, $triggerId);
} finally {
$cloudBuildClient->close();
}
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.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
getWorkerPool
Returns information about a WorkerPool
.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$response = $cloudBuildClient->getWorkerPool();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ name
string
The field will contain name of the resource requested, for example: "projects/project-1/workerPools/workerpool-name"
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
listBuildTriggers
Lists existing BuildTrigger
s.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
// Iterate over pages of elements
$pagedResponse = $cloudBuildClient->listBuildTriggers($projectId);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $cloudBuildClient->listBuildTriggers($projectId);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$cloudBuildClient->close();
}
projectId
string
Required. ID of the project for which to list BuildTriggers.
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
listBuilds
Lists previously requested builds.
Previously requested builds may still be in-progress, or may have finished successfully or unsuccessfully.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
// Iterate over pages of elements
$pagedResponse = $cloudBuildClient->listBuilds($projectId);
foreach ($pagedResponse->iteratePages() as $page) {
foreach ($page as $element) {
// doSomethingWith($element);
}
}
// Alternatively:
// Iterate through all elements
$pagedResponse = $cloudBuildClient->listBuilds($projectId);
foreach ($pagedResponse->iterateAllElements() as $element) {
// doSomethingWith($element);
}
} finally {
$cloudBuildClient->close();
}
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
listWorkerPools
List project's WorkerPools
.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$response = $cloudBuildClient->listWorkerPools();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ parent
string
ID of the parent project.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
receiveTriggerWebhook
ReceiveTriggerWebhook [Experimental] is called when the API receives a webhook request targeted at a specific trigger.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$response = $cloudBuildClient->receiveTriggerWebhook();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ 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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
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 Google 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.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$id = 'id';
$operationResponse = $cloudBuildClient->retryBuild($projectId, $id);
$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->retryBuild($projectId, $id);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudBuildClient->resumeOperation($operationName, 'retryBuild');
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();
}
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\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
runBuildTrigger
Runs a BuildTrigger
at a particular source revision.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$triggerId = 'trigger_id';
$operationResponse = $cloudBuildClient->runBuildTrigger($projectId, $triggerId);
$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->runBuildTrigger($projectId, $triggerId);
$operationName = $operationResponse->getName();
// ... do other work
$newOperationResponse = $cloudBuildClient->resumeOperation($operationName, 'runBuildTrigger');
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();
}
projectId
string
Required. ID of the project.
triggerId
string
Required. ID of the trigger.
optionalArgs
array
Optional.
↳ source
RepoSource
Source to build against this trigger.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
updateBuildTrigger
Updates a BuildTrigger
by its project ID and trigger ID.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$projectId = 'project_id';
$triggerId = 'trigger_id';
$trigger = new BuildTrigger();
$response = $cloudBuildClient->updateBuildTrigger($projectId, $triggerId, $trigger);
} finally {
$cloudBuildClient->close();
}
projectId
string
Required. ID of the project that owns the trigger.
triggerId
string
Required. ID of the BuildTrigger
to update.
trigger
optionalArgs
array
Optional.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
updateWorkerPool
Update a WorkerPool
.
This API is experimental.
Sample code:
$cloudBuildClient = new CloudBuildClient();
try {
$response = $cloudBuildClient->updateWorkerPool();
} finally {
$cloudBuildClient->close();
}
optionalArgs
array
Optional.
↳ name
string
The field will contain name of the resource requested, for example: "projects/project-1/workerPools/workerpool-name"
↳ workerPool
WorkerPool
WorkerPool
resource to update.
↳ retrySettings
RetrySettings|array
Retry settings to use for this call. Can be a Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\Cloud\Build\V1\Gapic\Google\ApiCore\RetrySettings for example usage.
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.