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 custom message #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bouk
Copy link

@bouk bouk commented Dec 18, 2020

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

@NotNoah
Copy link

NotNoah commented Mar 22, 2021

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?

@henrahmagix
Copy link

henrahmagix commented Apr 7, 2021

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 #95 and #90 (comment)

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

@mikesoule
Copy link

Trying to get some movement on this one. I published a proposed message format here: #95 (comment).

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.

@cristian-moreno-ruiz
Copy link

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!

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

Successfully merging this pull request may close these issues.

Add trigger name to slack notification
5 participants