Alexander Richter
Alexander Richter

Reputation: 91

Invalid Argument Error in Google Cloud Build/GitHub

I have been trying to integrate Google Cloud Build with my GitHub account. I have set up working build triggers in the past for other projects on GCP - but with this one, I just can't get it to work reliably. Here is what I did:

  1. Install the Google Cloud Build App on GitHub and link it to my Google Cloud Account.
  2. Connected to my GitHub repository in Google Cloud Build. As source, I selected "GitHub (Cloud Build GitHub App)".
  3. Let Cloud Build create its default trigger for me - just to make sure that the settings are correct.

Now, when manually running the default trigger, I always receive the following error message after selecting my branch: "Failed to trigger build: Request contains an invalid argument." Here is what that looks like:

Invalid Argument Error on Google Cloud Build

The trigger also does not work when invoked through a new commit in the GitHub repository. There are two different errors I have spotted through the GitHub UI:

  1. The GitHub Cloud Build Action essentially reports the same error as Cloud Build itself when manually invoking the build and immediately fails:

GitHub error 1

  1. The GitHub Cloud Build Action is queued/started, but never actually does anything. In this case, Cloud Build does not even seem to know about the build that was triggered by GitHub. The action will remain in this state for hours, even though Cloud Build should usually cancel builds after 10 minutes by default.

GitHub error 2

Here are some things that I've tried so far to mitigate the issue:

At this point, I seem to be stuck and I would be super grateful for any advice/tip that could somehow push me in the right direction.

One more thing that I should note: I have had the triggers working for a while in this project. They stopped working some time after I renamed my master branch on GitHub to "production". I don't know if that has anything to do with my triggers failing though.

Upvotes: 7

Views: 10017

Answers (1)

twiz
twiz

Reputation: 10608

I found that this can be caused when you have an "invalid" CloudBuild config file (e.g. cloudbuild.yaml).

This threw me off, because it doesn't necessarily mean it is invalid YAML or JSON, just that it is not what CloudBuild expects.

In my case, I defined a secretEnv value, but had removed the step that utilized it. Apparently, CloudBuild does not allow secretEnv values to go unused, which resulted in the cryptic error message:

Failed to trigger build: Request contains an invalid argument.

In case that isn't clear, here is an example of a config file that will fail:

steps:
  - name: "gcr.io/cloud-builders/docker"
    entrypoint: "bash"
    args: ["-c", "docker login --username=user-name --password=$$PASSWORD"]
    secretEnv: ["PASSWORD"]
secrets:
  - kmsKeyName: projects/project-id/locations/global/keyRings/keyring-name/cryptoKeys/key-name
    secretEnv:
      PASSWORD: "encrypted-password"
      UNUSED_PASSWORD: "another-encrypted-password"

UNUSED_PASSWORD is never actually used anywhere, so this will fail.

Since this error message is so vague, I assume there are other scenarios that could cause this same problem, so take this as just an example of the type of mistakes to look for.

Upvotes: 4

Related Questions