Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloudbuild.json error when attempting to upload a new clound function from FireStore create event

Hi All!

I am getting the error "Failed to trigger build: failed unmarshalling build config cloudbuild.json: json: cannot unmarshal array into Go value of type string " when attempting to build the following config file:

```

{
"steps": [
{
"name": "gcr.io/google.com/cloudsdktool/cloud-sdk",
"args": [
"gcloud",
"functions",
"deploy",
[
"validator-data"
],
"--region=us-west1",
"--source=.",
"--trigger-http",
"--runtime=nodejs18"
]
}
]
}
```

I manually built this in the UI, but am trying to deploy from a git repo for obvious reasons.

Any idea why this may not be building? Apologies if this has been covered but the docs don't have any examples for FireStore cloud functions.

I used the following docs to create this:

https://cloud.google.com/build/docs/deploying-builds/deploy-functions

https://cloud.google.com/functions/docs/calling/cloud-firestore#deploying_your_function

Solved Solved
0 3 2,067
1 ACCEPTED SOLUTION

The issue with your cloudbuild.json configuration file is that you are passing an array as an argument to the gcloud functions deploy command. Specifically, the ["validator-data"] array in the args field.

Instead, you should pass the function name as a string directly, like this: 

{
"steps": [
{
"name": "gcr.io/google.com/cloudsdktool/cloud-sdk",
"args": [
"gcloud",
"functions",
"deploy",
"validator-data", // Function name passed as a string
"--region=us-west1",
"--source=.",
"--trigger-http",
"--runtime=nodejs18"
]
}
]
}

This should resolve the "cannot unmarshal array into Go value of type string" error and allow you to deploy your Cloud Function from your Git repository using Cloud Build.

View solution in original post

3 REPLIES 3

The issue with your cloudbuild.json configuration file is that you are passing an array as an argument to the gcloud functions deploy command. Specifically, the ["validator-data"] array in the args field.

Instead, you should pass the function name as a string directly, like this: 

{
"steps": [
{
"name": "gcr.io/google.com/cloudsdktool/cloud-sdk",
"args": [
"gcloud",
"functions",
"deploy",
"validator-data", // Function name passed as a string
"--region=us-west1",
"--source=.",
"--trigger-http",
"--runtime=nodejs18"
]
}
]
}

This should resolve the "cannot unmarshal array into Go value of type string" error and allow you to deploy your Cloud Function from your Git repository using Cloud Build.

Oh that's so weird, thank you for that.  The solution in GCP docs has the name in an array.  Do you know why they included that?

https://cloud.google.com/build/docs/deploying-builds/deploy-functions

 

The reason why the function name is included in an array in the cloudbuild.json file is to provide support for multiple functions in a single repository. If you have multiple functions in your repository, you can specify the name of each function in the functions array of the cloudbuild.json file, and Cloud Build will build and deploy each function as a separate Cloud Function.

If you only have one function in your repository, you can simply specify the function name as a string, without using an array. This should work just fine and should not cause any issues.