0
votes

I'm trying to change a trigger using REST API, specifically https://cloud.google.com/build/docs/api/reference/rest/v1/projects.triggers/patch. Note that I'm able to use curl and list all the triggers. Also I tried to download the trigger in JSON using https://cloud.google.com/build/docs/api/reference/rest/v1/projects.triggers/get (which works perfectly) but when I tried to upload the same file the error is always:

{
  "error": {
    "code": 400,
    "message": "exactly 1 build config required, got: 0",
    "status": "INVALID_ARGUMENT"
  }
}

if I try to upload an invalid Json correctly it gives error parsing JSON, so surely it's trying to parse using JSON format.

So I tried the same experiment using "Try it!" button on Google page which opens Google APIs explorer. Same results. The interface gave me a warning that some fields are only output so I tried also to remove these fields but I got the same error.

The file I'm trying to upload is (changed some strings to remove company name)

{
  "description": "Push to any branch",
  "github": {
    "push": {
      "branch": ".*"
    },
    "owner": "company",
    "name": "repo-utils"
  },
  "tags": [
    "github-default-push-trigger"
  ],
  "name": "default-push-trigger-127"
}
1
Had a look at nieldw.medium.com/… and stackoverflow.com/questions/64118275/…, it seems I'm doing the same but it does not help - Frediano Ziglio

1 Answers

0
votes

I think I found the issue. Google API seems to require either build or filename to be passed to specify a way to build. On the other hand the web interface allows to insert an Autodetect option for the build which will try to look for either cloudbuild.yaml or Dockerfile in the root directory. If you specify Autodetect on the web interface the Json configuration won't have either build or filename so when you try to import back that configuration it will fail.

I tried to pass filename as empty string, the web interface shows a cloudbuild.yaml (which is present) but the execution of the trigger fails.

So it seems there's no way to insert a Autodetect mode trigger using the API.