googleapis / nodejs-cloudbuild

This repository is deprecated. All of its content and history has been moved to googleapis/google-cloud-node.
https://cloud.google.com/cloud-build/docs/
Apache License 2.0
38 stars 13 forks source link

runBuildTrigger does not include location as part of trigger path #332

Closed dgershin closed 2 years ago

dgershin commented 2 years ago

Environment details

Steps to reproduce

Call method runBuildTrigger(), passing in the project Id and Trigger Id

const cb = new CloudBuildClient(); const [resp] = await cb.runBuildTrigger({ projectId, triggerId }); const [build] = await resp.promise();

Returns Error: 5 NOT_FOUND: triggerError spanner trigger ([project number], [triggerId]) not found

In searching the logs, the resource name passed in the API request is projects/[projectId]/triggers/[triggerId]

The actual resource name should be projects/[projectId]/locations/[location]/triggers/[triggerId]

The client library does include the location as a part of the resource name, so it does not find the trigger

grayside commented 2 years ago

Hello @dgershin , thanks for opening this issue and including helpful details.

Confirmed the docs show projects/[projectId]/locations/[location]/triggers/[triggerId] at https://cloud.google.com/build/docs/api/reference/rest/v1/projects.locations.triggers/run.

Looking at the generated sample, it seems there may be some configuration mismatch in the library, as the sample has a commented out parameter for the correct trigger name, but doesn't use that parameter or otherwise have an obvious way to recreate it.

grayside commented 2 years ago

After additional research, this looks like it will help you run a trigger:

const projectId = 'PROJECT_NAME';
const triggerId = 'TRIGGER_NAME';
const name = `projects/${projectId}/locations/global/triggers/${triggerId}`;

// Imports the Cloudbuild library
const {CloudBuildClient} = require('@google-cloud/cloudbuild').v1;

// Instantiates a client
const cloudbuildClient = new CloudBuildClient();

async function callRunBuildTrigger() {
  // Construct request
  const request = {
    name,
    projectId,
    triggerId,
  };

  // Run request
  const [operation] = await cloudbuildClient.runBuildTrigger(request);
  const [response] = await operation.promise();
  console.log(response);
}

Thanks for the assist @sofisl and @alexander-fenster