{"record":{"id":"87de5aad4254d33d","repo":"apache/beam","slug":"failed-to-build-python-sdk-container-image-on-google-cloud","errorCode":null,"errorMessage":"Failed to build python sdk container image on google cloud build, please check build log for error.","messagePattern":"Failed to build python sdk container image on google cloud build, please check build log for error\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/runners/portability/sdk_container_builder.py","lineNumber":296,"sourceCode":"    build_id, log_url = self._get_cloud_build_id_and_log_url(build.metadata)\n    _LOGGER.info(\n        'Building sdk container with Google Cloud Build, this may '\n        'take a few minutes, you may check build log at %s' % log_url)\n\n    # block until build finish, if build fails exception will be raised and\n    # stops the job submission.\n    response = self._cloudbuild_client.get_build(\n        request=cloud_build_types.GetBuildRequest(\n            id=build_id, project_id=project_id))\n    while response.status in [cloud_build_types.Build.Status.QUEUED,\n                              cloud_build_types.Build.Status.PENDING,\n                              cloud_build_types.Build.Status.WORKING]:\n      time.sleep(10)\n      response = self._cloudbuild_client.get_build(\n          cloud_build_types.GetBuildRequest(id=build_id, project_id=project_id))\n\n    if response.status != cloud_build_types.Build.Status.SUCCESS:\n      raise RuntimeError(\n          'Failed to build python sdk container image on google cloud build, '\n          'please check build log for error.')\n\n    _LOGGER.info(\n        \"Python SDK container pre-build finished in %.2f seconds\" %\n        (time.time() - now))\n    _LOGGER.info(\n        \"Python SDK container built and pushed as %s.\" % container_image_name)\n\n  def _upload_to_gcs(self, local_file_path, gcs_location):\n    bucket_name, blob_name = self._get_gcs_bucket_and_name(gcs_location)\n    _LOGGER.info('Starting GCS upload to %s...', gcs_location)\n    from google.cloud import storage\n    from google.cloud.exceptions import Forbidden\n    from google.cloud.exceptions import NotFound\n    try:\n      bucket = self._storage_client.get_bucket(bucket_name)\n      blob = bucket.get_blob(blob_name)","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/runners/portability/sdk_container_builder.py#L278-L314","documentation":"The Google Cloud Build container builder polls the build via get_build until it leaves the working/queued states. If the final status is anything other than SUCCESS, RuntimeError is raised telling the user to consult the Cloud Build log, since the actual failure detail lives there.","triggerScenarios":"_invoke_docker_build_and_push on the Cloud Build path submits a build to Google Cloud Build, polls with _cloudbuild_client.get_build, and the build finishes with status FAILURE, TIMEOUT, CANCELLED, or INTERNAL_ERROR instead of SUCCESS.","commonSituations":"Dockerfile steps failing inside Cloud Build (pip resolution errors, network egress blocked); build exceeding the Cloud Build timeout; project quota or API not enabled; push step failing due to insufficient IAM permissions on the target GCR/Artifact Registry repo.","solutions":["Open the Cloud Build console (or 'gcloud builds log <build-id>') to read the failure reason","Fix the failing build step shown in the log (dependency/network errors)","Increase the Cloud Build timeout if the build timed out","Verify the Cloud Build service account has permission to push to the target registry"],"exampleFix":"// before\ncloudbuild config with default 10m timeout; heavy build times out\n// after\noptions = {'timeout': '1800s'}  # raise timeout in the Build request","handlingStrategy":"retry","validationCode":"from google.api_core import exceptions\nclient = cloudbuild_v1.services.cloud_build.CloudBuildClient()\n# pre-flight: API enabled and service account can push\ntry:\n    client.get_build(cloud_build_types.GetBuildRequest(id='0', project_id=project))\nexcept exceptions.PermissionDenied:\n    raise SystemExit('Enable cloudbuild.googleapis.com and grant build rights')","typeGuard":"def build_succeeded(status) -> bool:\n    from google.cloud.devtools import cloudbuild_v1 as cloud_build_types\n    return status == cloud_build_types.Build.Status.SUCCESS","tryCatchPattern":"try:\n    builder.build_container_image(...)\nexcept RuntimeError as e:\n    if 'google cloud build' in str(e):\n        logger.error('Cloud Build failed; fetch logs: gcloud builds list --filter=%s', build_id)\n        raise SystemExit(6)","preventionTips":["Set a generous Cloud Build timeout for SDK image builds","Pre-warm the image once and reuse it rather than building per-run","Ensure the Cloud Build service account has write access to the target registry","Check gcloud builds log output as part of CI on failure"],"tags":["apache-beam","google-cloud-build","container-image","ci"],"backgroundTag":"api-error-response","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}