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

Slack custom message

Open bouk opened this issue 3 years ago • 4 comments

Here I'm adding support for defining a custom template to the Slack notifier. Pretty straightforward, just using text/template with a default template that's the same as what the Sprintf does right now.

I also made a small fix to pass down the context when submitting the webhook, just saw that this was not being done before.

Closes #90

bouk avatar Dec 18 '20 10:12 bouk

What are the chances this gets merged/we get something like this? Would like a way to configure the slack notifications with trigger name or repository included in the slack notifications at the minimum. Is the recommended way to create an image based off this PR for now?

NotNoah avatar Mar 22 '21 19:03 NotNoah

If you're using an image based off this PR, here's a template where you can get a message out of the build via the build env:

textTemplate: 'Here is my custom message: {{if .Options}}{{range .Options.Env}}{{if ge (len .) 10}}{{if eq (slice . 0 10) "SLACK_MSG="}}{{slice . 10}}{{end}}{{end}}{{else}}default if SLACK_MSG env not found{{end}}{{else}}default if no options{{end}}'

where the env var is called SLACK_MSG, e.g. in a cloudbuild yaml file:

options:
  env:
    - SLACK_MSG=print me to slack

and you will see:

Here is my custom message: print me to slack

If you rename the env var, remember to replace the use of 10 with the length of YOUR_VAR_HERE= in order to slice the string correctly (it was the only way I could get go template to pull out a cloudbuild env var without having to add additional functions or data).


Thanks @bouk for this =)

@NotNoah The Cloud Build team are working on a requirements doc to do this in their own way because they "want to have a standardized implementation for all notifiers": see https://github.com/GoogleCloudPlatform/cloud-build-notifiers/issues/95 and https://github.com/GoogleCloudPlatform/cloud-build-notifiers/issues/90#issuecomment-778487181

So I'm looking forward to when we can do this without having to build our own image based on this PR =)

henrahmagix avatar Apr 07 '21 14:04 henrahmagix

Trying to get some movement on this one. I published a proposed message format here: https://github.com/GoogleCloudPlatform/cloud-build-notifiers/issues/95#issuecomment-905873273.

My format is not a serious proposal other than to get the Cloud Build Team moving on the requirements piece of this. I reckon those of you who worked on this PR and are actively using an image based on it would have better input on what the message format should be.

mikesoule avatar Aug 25 '21 21:08 mikesoule

Is there a way to get the trigger name, or other stuff through this PR? Or does it require additional changes? I'd be happy to use this PR to setup my custom triggers, even before merging, but I'm not sure how to do it.

Thanks!

cristian-moreno-ruiz avatar Sep 21 '21 21:09 cristian-moreno-ruiz