Search code examples
google-cloud-buildgoogle-workflows

googleapis.cloudbuild.v1.projects.triggers.run INVALID_ARGUMENT with no clues


Trying to reproduce this command from Google Workflow:

gcloud builds triggers run aaa-bbb-ccc-ddd-eee --region="us-central1" --project=prj-dev3 --branch="ci-cd"

Where xxx is the project number, prj-dev3 is the project id and aaa-bbb-ccc-ddd-eee is the trigger id

I try using googleapis.cloudbuild.v1.projects.locations.triggers.run:

    - buildSite:
        call: googleapis.cloudbuild.v1.projects.locations.triggers.run
        args:
          name: projects/xxx/locations/us-central1/builds/aaa-bbb-ccc-ddd-eee
          body:
            projectId: prj-dev3
            triggerId: aaa-bbb-ccc-ddd-eee
            source:
              branchName: "ci-cd"

and the error is even worse:

HTTP server responded with error code 400
in step "buildSite", routine "main", line: 100
{
  "body": "<html lang=\"en\" dir=ltr><meta charset=utf-8><meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\"><title>Error 400 (Bad Request)!!1</title><style nonce=\"Al2U9MAVutAwFsudi6tIqg\">*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{color:#222;text-align:unset;margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px;}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}pre{white-space:pre-wrap;}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}</style><main id=\"af-error-container\" role=\"main\"><a href=//www.google.com><span id=logo aria-label=Google role=img></span></a><p><b>400.</b> <ins>That’s an error.</ins><p>The server cannot process the request because it is malformed. It should not be retried. <ins>That’s all we know.</ins></main>",
  "code": 400,
  "headers": {
    "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
    "Cache-Control": "no-cache, no-store, max-age=0, must-revalidate",
    "Content-Length": "1695",
    "Content-Type": "text/html; charset=utf-8",
    "Date": "Sun, 09 Feb 2025 12:00:18 GMT",
    "Expires": "Mon, 01 Jan 1990 00:00:00 GMT",
    "P3p": "CP=\"This is not a P3P policy! See g.co/p3phelp for more info.\"",
    "Pragma": "no-cache",
    "Server": "ESF",
    "Set-Cookie": "NID=521=zL9ULQim19xLeNkYKvp0PJ82c_KDJ0olqVlQBNy62wkT6f_k91V2h3Wh9qpEgMZbziNtcFOsBs2A9rnNJjXqDi9_7EbCBSrK6YIyUrpbHG469mtQ7MN1VIYI56l8k0e9u8UHdYAkamsRD8PFaZgO62cLmYMSI_j7w1D4q-ilfrc; expires=Mon, 11-Aug-2025 12:00:18 GMT; path=/; domain=.cloudbuild.googleapis.com; HttpOnly",
    "X-Content-Type-Options": "nosniff",
    "X-Xss-Protection": "0"
  },
  "message": "HTTP server responded with error code 400",
  "tags": [
    "HttpError"
  ]
}

I don't have a clue about where is the error and no idea how to debug the error. I'm so desperate and frustrated. :_(

Any idea or advise?

Thanks!

FIRST TEST: I tried this before, but leapis.cloudbuild.v1.projects.triggers.run is for global triggers, so moving to the new locations version.

    - buildSite:
        call: googleapis.cloudbuild.v1.projects.triggers.run
        args:
          projectId: prj-dev3
          triggerId: aaa-bbb-ccc-ddd-eee
          name: projects/xxx/locations/us-central1/builds/aaa-bbb-ccc-ddd-eee
          body:
            branchName: "ci-cd"

From the cli works fine, but the step gives this error:

HTTP server responded with error code 400
in step "buildSite", routine "main", line: 100
{
  "body": {
    "error": {
      "code": 400,
      "message": "Request contains an invalid argument.",
      "status": "INVALID_ARGUMENT"
    }
  },
  "code": 400,
  "headers": {
    "Alt-Svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
    "Content-Length": "127",
    "Content-Type": "application/json; charset=UTF-8",
    "Date": "Sun, 09 Feb 2025 11:13:29 GMT",
    "Server": "ESF",
    "Vary": "Origin, X-Origin, Referer",
    "X-Content-Type-Options": "nosniff",
    "X-Frame-Options": "SAMEORIGIN",
    "X-Xss-Protection": "0"
  },
  "message": "HTTP server responded with error code 400",
  "tags": [
    "HttpError"
  ]
}

Solution

  • It's unclear in the documentation but APIs Explorer is very useful for understanding the shape of Google's APIs.

    For example Cloud Build API's projects.locations.triggers.run documents the fully-qualified (resource) name:

    projects/{project}/locations/{location}/triggers/{trigger}
    

    I think this is generally (!?) (always?) the Project ID not the Project Number.

    Because you're using Workflows there is a translation step from Workflows' googleapis.cloudbuild.v1.projects.locations.triggers.run to the Cloud Build v1 API' s method and -- curiously -- this indicates a mismatch between the types; the Cloud Build v1 API's projects.locations.triggers.run method takes a source of type RepoSource that is documented as requiring repoName but you confirm that it isn't.

    It would be interesting to see how gcloud builds triggers run is invoking the API by appending --log-http to your command.