Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
This repository was archived by the owner on Mar 19, 2026. It is now read-only.

LRO do not work as expected for Cloud Build #606

Closed

Description

@bcoe

Bug

When using the Cloud Build API, I initially attempted to await builds as a long running operation:

  const [resp] = await cb.runBuildTrigger({
    projectId: project,
    triggerId: args.trigger,
    source: {
      projectId: project,
      branchName: 'master', // TODO: It might fail if we change the default branch.
      substitutions: {
        _GITHUB_TOKEN: token.token,
        _PR: args.pr.toString(),
        _PR_BRANCH: prData.head.ref,
        _PR_OWNER: prOwner,
        _REPOSITORY: prRepo,
        // _CONTAINER must contain the image digest. For example:
        // gcr.io/repo-automation-tools/nodejs-post-processor**@1234abcd**
        // TODO: read this from OwlBot.yaml.
        _CONTAINER: args.image,
        _DEFAULT_BRANCH: args.defaultBranch ?? 'master',
      },
    },
  });
const [build] = await resp.promise();

This code did not successfully wait for a build to complete and return a build object.

As a workaround we implemented our own polling behavior (see here).

Expected Behavior

const [build] = await resp.promise(); waits for build to complete and returns the build object.

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jul 13, 2021
  2. hkdevandla commented on Oct 20, 2021

    @hkdevandla

    @bcoe , is this still an issue and specific to only Cloud Build or impacting more broader set of APIs?

  3. bcoe commented on Oct 27, 2021

    @bcoe
    Author

    is this still an issue and specific to only Cloud Build or impacting more broader set of APIs

    @hkdevandla I happened to notice this issue as a consumer of Cloud Build myself (we're using it for OwlBot). Not sure if it's happening for additional APIs.

    I can try to provide a better isolated example -- I think Cloud Build is a good candidate for testing long running operations behavior, since builds can easily take a minute or two, maybe we just haven't noticed the behavior elsewhere?

  4. hkdevandla commented on Jan 20, 2022

    @hkdevandla

    @summer-ji-eng , please check if we can tackle this during the fixit. Thanks!

  5. summer-ji-eng commented on Feb 12, 2022

    @summer-ji-eng
    Contributor

    I hope that I bring a good news here. I finally successfully create Build and triggerBuild use forked gapic-generator-typescript.

    The LRO RunBuildTrigger work as expected, it return a promise. It is able to wait for the promise complete return build object.

    const [build] = await resp.promise();
    

    The build object receiving is identical to the object get from polling service (code)

    The sample build output I received on local:

    {
      steps: [
        BuildStep {
          env: [],
          args: [Array],
          waitFor: [],
          secretEnv: [],
          volumes: [],
          name: 'gcr.io/cloud-builders/docker',
          timing: [TimeSpan],
          status: 3,
          pullTiming: [TimeSpan]
        }
      ],
      images: [
        'us-central1-docker.pkg.dev/xxxxxx/quickstart-docker-repo/quickstart-image:tag1'
      ],
      substitutions: {
        COMMIT_SHA: 'xxx',
        SHORT_SHA: 'xxx',
        BRANCH_NAME: 'main',
        REF_NAME: 'main',
        TRIGGER_NAME: 'triggerTest',
        TRIGGER_BUILD_CONFIG_PATH: 'cloudbuild.yaml',
        REPO_NAME: 'xxxx',
        REVISION_ID: 'xxxx'
      },
      tags: [ 'xxxx' ],
      secrets: [],
      timing: {
        PUSH: TimeSpan { startTime: [Timestamp], endTime: [Timestamp] },
        FETCHSOURCE: TimeSpan { startTime: [Timestamp], endTime: [Timestamp] },
        BUILD: TimeSpan { startTime: [Timestamp], endTime: [Timestamp] }
      },
      warnings: [],
      id: 'xxxxx',
      status: 3,
      source: Source {},
      createTime: Timestamp {
        seconds: Long { low: 1644634605, high: 0, unsigned: false },
        nanos: 292596826
      },
      startTime: Timestamp {
        seconds: Long { low: 1644634605, high: 0, unsigned: false },
        nanos: 802775985
      },
      finishTime: Timestamp {
        seconds: Long { low: 1644634615, high: 0, unsigned: false },
        nanos: 727844000
      },
      results: Results {
        images: [ [BuiltImage] ],
        buildStepImages: [
          'sha256:xxx'
        ],
        buildStepOutputs: [ <Buffer > ]
      },
      timeout: Duration { seconds: Long { low: 600, high: 0, unsigned: false } },
      projectId: 'xxxx',
      logsBucket: 'xxx',
      sourceProvenance: SourceProvenance { fileHashes: {} },
      buildTriggerId: 'xxx',
      options: BuildOptions {
        sourceProvenanceHash: [],
        env: [],
        secretEnv: [],
        volumes: [],
        substitutionOption: 1,
        logging: 1,
        dynamicSubstitutions: true,
        pool: PoolOption {}
      },
      logUrl: 'https://console.cloud.google.com/cloud-build/builds/xxxx?project=xxx',
      artifacts: Artifacts {
        images: [
          'us-central1-docker.pkg.dev/xxx/quickstart-docker-repo/quickstart-image:tag1'
        ]
      },
      queueTtl: Duration { seconds: Long { low: 3600, high: 0, unsigned: false } },
      name: 'projects/xxx/locations/global/builds/xxx'
    }
    

    @bcoe I close this ticket for now. But please reopen if it is still have issue on your side, I could use your build to debug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions