airflow.providers.google.cloud.hooks.cloud_build

Hook for Google Cloud Build service.

Module Contents

Classes

CloudBuildHook

Hook for the Google Cloud Build Service.

CloudBuildAsyncHook

Asynchronous Hook for the Google Cloud Build Service.

Attributes

TIME_TO_SLEEP_IN_SECONDS

airflow.providers.google.cloud.hooks.cloud_build.TIME_TO_SLEEP_IN_SECONDS = 5[source]
class airflow.providers.google.cloud.hooks.cloud_build.CloudBuildHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Hook for the Google Cloud Build Service.

Parameters
  • gcp_conn_id (str) – The connection ID to use when fetching connection info.

  • impersonation_chain (str | collections.abc.Sequence[str] | None) – Optional service account to impersonate using short-term credentials, or chained list of accounts required to get the access_token of the last account in the list, which will be impersonated in the request. If set as a string, the account must grant the originating account the Service Account Token Creator IAM role. If set as a sequence, the identities from the list must grant Service Account Token Creator IAM role to the directly preceding identity, with first account from the list granting this role to the originating account.

wait_for_operation(operation, timeout=None)[source]

Wait for long-lasting operation to complete.

get_conn(location='global')[source]

Retrieve the connection to Google Cloud Build.

Parameters

location (str) – The location of the project.

Returns

Google Cloud Build client object.

Return type

google.cloud.devtools.cloudbuild_v1.CloudBuildClient

cancel_build(id_, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Cancel a build in progress.

Parameters
  • id – The ID of the build.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

create_build_without_waiting_for_result(build, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Start a build with the specified configuration without waiting for it to finish.

Parameters
  • build (dict | google.cloud.devtools.cloudbuild_v1.types.Build) – The build resource to create. If a dict is provided, it must be of the same form as the protobuf message google.cloud.devtools.cloudbuild_v1.types.Build

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

create_build(build, project_id=PROVIDE_PROJECT_ID, wait=True, retry=DEFAULT, timeout=None, metadata=())[source]

Start a build with the specified configuration.

Parameters
  • build (dict | google.cloud.devtools.cloudbuild_v1.types.Build) – The build resource to create. If a dict is provided, it must be of the same form as the protobuf message google.cloud.devtools.cloudbuild_v1.types.Build

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • wait (bool) – Optional, wait for operation to finish.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

create_build_trigger(trigger, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Create a new BuildTrigger.

Parameters
  • trigger (dict | google.cloud.devtools.cloudbuild_v1.types.BuildTrigger) – The BuildTrigger to create. If a dict is provided, it must be of the same form as the protobuf message google.cloud.devtools.cloudbuild_v1.types.BuildTrigger

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

delete_build_trigger(trigger_id, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Delete a BuildTrigger by its project ID and trigger ID.

Parameters
  • trigger_id (str) – The ID of the BuildTrigger to delete.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

get_build(id_, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Return information about a previously requested build.

Parameters
  • id – The ID of the build.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

get_build_trigger(trigger_id, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Return information about a BuildTrigger.

Parameters
  • trigger_id (str) – The ID of the BuildTrigger to get.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

list_build_triggers(location='global', project_id=PROVIDE_PROJECT_ID, page_size=None, page_token=None, retry=DEFAULT, timeout=None, metadata=())[source]

List existing BuildTriggers.

Parameters
  • project_id (str) – Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • location (str) – The location of the project.

  • page_size (int | None) – Optional, number of results to return in the list.

  • page_token (str | None) – Optional, token to provide to skip to a particular spot in the list.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

list_builds(location='global', project_id=PROVIDE_PROJECT_ID, page_size=None, page_token=None, filter_=None, retry=DEFAULT, timeout=None, metadata=())[source]

List previously requested builds.

Parameters
  • project_id (str) – Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the Google Cloud connection is used.

  • location (str) – The location of the project.

  • page_size (int | None) – Optional, number of results to return in the list.

  • page_token (int | None) – Optional, token to provide to skip to a particular spot in the list.

  • filter – Optional, the raw filter text to constrain the results.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

retry_build(id_, project_id=PROVIDE_PROJECT_ID, wait=True, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Create a new build using the original build request; may or may not result in an identical build.

Parameters
  • id – Build ID of the original build.

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • wait (bool) – Optional, wait for operation to finish.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

run_build_trigger(trigger_id, source, project_id=PROVIDE_PROJECT_ID, wait=True, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Run a BuildTrigger at a particular source revision.

Parameters
  • trigger_id (str) – The ID of the trigger.

  • source (dict | google.cloud.devtools.cloudbuild_v1.types.RepoSource) – Source to build against this trigger. If a dict is provided, it must be of the same form as the protobuf message google.cloud.devtools.cloudbuild_v1.types.RepoSource

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • wait (bool) – Optional, wait for operation to finish.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

update_build_trigger(trigger_id, trigger, project_id, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Update a BuildTrigger by its project ID and trigger ID.

Parameters
  • trigger_id (str) – The ID of the trigger.

  • trigger (dict | google.cloud.devtools.cloudbuild_v1.types.BuildTrigger) – The BuildTrigger to create. If a dict is provided, it must be of the same form as the protobuf message google.cloud.devtools.cloudbuild_v1.types.BuildTrigger

  • project_id (str) – Optional, Google Cloud Project project_id where the function belongs. If set to None or missing, the default project_id from the GCP connection is used.

  • retry (google.api_core.retry.Retry | google.api_core.gapic_v1.method._MethodDefault) – Optional, a retry object used to retry requests. If None is specified, requests will not be retried.

  • timeout (float | None) – Optional, the amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

  • metadata (collections.abc.Sequence[tuple[str, str]]) – Optional, additional metadata that is provided to the method.

  • location (str) – The location of the project.

class airflow.providers.google.cloud.hooks.cloud_build.CloudBuildAsyncHook(gcp_conn_id='google_cloud_default', impersonation_chain=None, **kwargs)[source]

Bases: airflow.providers.google.common.hooks.base_google.GoogleBaseHook

Asynchronous Hook for the Google Cloud Build Service.

async get_cloud_build(id_, project_id=PROVIDE_PROJECT_ID, retry=DEFAULT, timeout=None, metadata=(), location='global')[source]

Retrieve a Cloud Build with a specified id.

Was this entry helpful?