Closed dgershin closed 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.
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
Environment details
@google-cloud/cloudbuild
version:^3.0.0Steps 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