cloud-build-notifiers icon indicating copy to clipboard operation
cloud-build-notifiers copied to clipboard

SlackNotifier Error "field template not found in type notifiers.Notification"

Open TeChn4K opened this issue 1 year ago • 2 comments

Hi guys,

I'm getting this error on deployment :

Container called exit(255).
/go-src/slack/main.go:33 +0x7b
...
line 10: field template not found in type notifiers.Notification
...
main.go: fatal error: failed to get config from GCS: failed to parse configuration from YAML at "xxx/slack/cloud-build/conf.yaml": yaml: unmarshal errors:

My config file seems reachable. When I specify a not existing config path, it throws a different error.

Any idea?

conf.yaml

apiVersion: cloud-build-notifiers/v1
kind: SlackNotifier
metadata:
  name: cloud-build-slack-notifier
spec:
  notification:
    delivery:
      webhookUrl:
        secretRef: webhook-url
    template:
      type: golang
      uri: gs://xxx/slack/cloud-build/message.json

  secrets:
    - name: webhook-url
      value: projects/xxx/secrets/xxx/versions/latest

message.json

[
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "Cloud Build {{.Build.ProjectId}} {{.Build.Id}} {{.Params.buildStatus}}"
      }
    },
    {
      "type": "divider"
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "View Build Logs"
      },
      "accessory": {
        "type": "button",
        "text": {
          "type": "plain_text",
          "text": "Logs"
        },
        "value": "click_me_123",
        "url": "{{.Build.LogUrl}}",
        "action_id": "button-action"
      }
    }
  ]
 gcloud run deploy slack-notify-cloud-build \
   --image=us-east1-docker.pkg.dev/gcb-release/cloud-build-notifiers/slack:slack-1.14.0 \
   --no-allow-unauthenticated \
   --update-env-vars=CONFIG_PATH=gs://xxx/slack/cloud-build/conf.yaml,PROJECT_ID=xxx

TeChn4K avatar Sep 14 '23 09:09 TeChn4K

When I update the conf.yaml to add params and filter, I get a new error ...

line 13: field template not found in type notifiers.Notification
line 8: field params not found in type notifiers.Notification
...
main.go: fatal error: failed to get config from GCS: failed to parse configuration from YAML at "xxx/slack/cloud-build/conf.yaml": yaml: unmarshal errors:


conf.yaml

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

  secrets:
    - name: webhook-url
      value: projects/xxx/secrets/xxx/versions/latest

TeChn4K avatar Sep 14 '23 09:09 TeChn4K

Hi, which version of the notifier are you using? I believe you need to be using 1.15 (or ideally latest) and you should get these errors resolved.

prabenzom avatar Oct 05 '23 16:10 prabenzom