Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slack Notifier failed to unmarshal templating JSON #145

Open
connelld-willa opened this issue Aug 12, 2022 · 6 comments
Open

Slack Notifier failed to unmarshal templating JSON #145

connelld-willa opened this issue Aug 12, 2022 · 6 comments

Comments

@connelld-willa
Copy link

connelld-willa commented Aug 12, 2022

I have been following these instructions on the GCP documentation page. I have done nothing custom beyond substituting variables.

However, it is not working and I see tons of error messages in the cloud run logs saying:

1 notifiers.go:549] failed to run SendNotification: failed to write Slack message: failed to unmarshal templating JSON: unexpected end of JSON input"

There is a somewhat similar closed issue here - and the solution was to pin an older version. If thats the case, what version should it be?

Also, how would I set the retry limit invocations to the cloud run service from pubsub? I think would have racked up quite the bill if I had not been looking.

@connelld-willa
Copy link
Author

UPDATE:
I redeployed with the previous version us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers/slack@sha256:357053acf6426028241d140c54f97581d9aa9cf70ffd6a92b0a71d2e7013f4b9

And it works fine. So my guess still, is there is something up with the latest version.

@dpkirchner
Copy link

Seems like this is the commit: b0668da

In which case, I'm wondering if one of the variables being passed to the template is has embedded quotes that need to be escaped. I'm looking at my cloud build pub/sub messages and I don't see an obvious problem, however. My best, crazy guess is that it has something to do with some unicode encoded equal sign in the "logUrl" variable.

The template looks for "projectId", "id", "status", and "logUrl". The first three are just plain ol' ASCII, no special characters, no quotes, etc. The fourth, logUrl, is https://console.cloud.google.com/cloud-build/builds/19f99583-3263-48f5-968f-a7e101823d42?project\u003d12345678. I'm thinking maybe it's that \u003d.

@d47id
Copy link

d47id commented Aug 22, 2022

@dpkirchner I agree that it's the commit you reference, but I don't think it's an issue with the template values. That commit wires the slack notifier up to use a golang template which gets populated over in notifiers.go.

I copied the new file slack.json into the cloud storage bucket where I have my slack notifier yaml configs, and added a template config to them:

apiVersion: cloud-build-notifiers/v1
kind: SlackNotifier
metadata:
  name: notifier-name
spec:
  notification:
    filter: build.status == Build.Status.SUCCESS
    delivery:
      webhookUrl:
        secretRef: webhook-url
    template:
      type: golang
      uri: gs://bucket-name/slack.json

That cleared the errors in the logs, although the notification is not the prettiest. I guess now I can customize it though.

Seems like the documentation needs to be updated to reflect that a template for slack attachment blocks needs to be configured.

@dandebiase
Copy link

Another workaround for folks using the slack notifier with the setup.sh shell script. I'm sure this will break the other notifiers though so don't utilize this if you mix them.

@@ -123,7 +123,7 @@ main() {
   DESTINATION_CONFIG_PATH="${DESTINATION_BUCKET_URI}/${SOURCE_CONFIG_BASENAME}"
   SOURCE_TEMPLATE_BASENAME=$(basename "${SOURCE_TEMPLATE_PATH}")
   DESTINATION_TEMPLATE_PATH="${DESTINATION_BUCKET_URI}/${SOURCE_TEMPLATE_BASENAME}"
-  IMAGE_PATH="us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers/${NOTIFIER_TYPE}:latest"
+  IMAGE_PATH="us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers/${NOTIFIER_TYPE}:slack-1.14.0"
   SERVICE_NAME="${NOTIFIER_TYPE}-notifier"
   SUBSCRIPTION_NAME="${NOTIFIER_TYPE}-subscription"
   INVOKER_SA="cloud-run-pubsub-invoker@${PROJECT_ID}.iam.gserviceaccount.com"

@ezeYaniv
Copy link
Contributor

ezeYaniv commented Mar 7, 2023

@dandebiase FYI, using this workaround throws the error below when I run the setup.sh script.

Deployment failed                                                                                                                                                                              
ERROR: (gcloud.run.deploy) The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable. Logs for this revision might contain more information.

@dang-hoang-hieu
Copy link

For those who face this error unmarsal JSON
my case was I accidentally had comments in yaml config & json file
like

          secretRef: webhook-url
      template:
        type: golang
        uri: gs://xxxx/slack-msg2.json # some comment here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants