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

Send messages to different slack channel based on trigger #23

Open
naseemkullah opened this issue May 30, 2019 · 8 comments
Open

Send messages to different slack channel based on trigger #23

naseemkullah opened this issue May 30, 2019 · 8 comments

Comments

@naseemkullah
Copy link
Contributor

Hello,

Although having a default slack channel to send notifications is desired, it would be nice to be able to override the channel for specific repos. Agree? And if so any ideas on how to implement this?

@Philmod
Copy link
Owner

Philmod commented May 30, 2019

Do you actually need this currently?
In my experience, we always have a single room with all the notifications to avoid spamming many rooms.

@naseemkullah
Copy link
Contributor Author

The feedback I get from my colleagues is that our GCB status channel is swamped with too many messages and they often do not pay attention as it is too noisey,
whereas if the repos they are concerned with's notifications were sent to the slack channel that concerns that specific service they would pay more attention.

@naseemkullah
Copy link
Contributor Author

Whta about adding "webhook rules" (Mapping of rules to webhook urls") in the config.json file, if any are defined they will be applied at runtime, if no rule matches or no rules are defined it will default to the good ol' SLACK_WEBHOOK_URL ... thoughts?

something along the lines of

{
  "SLACK_WEBHOOK_URL": "https://hooks.slack.com/services/XXX",
  "SLACK_WEBHOOK_RULES": [{
      "rule": {
        "repoName": "foo"
      },
      "slack_webhook_url": "https://hooks.slack.com/services/XYZ"
    },
    {
      "rule": {
        "repoName": "bar",
        "maybesomething": "maybesomethingelse"
      },
      "slack_webhook_url": "https://hooks.slack.com/services/ZZZ"
    }
  ]
}

@naseemkullah
Copy link
Contributor Author

naseemkullah commented Aug 24, 2019

slackapi/node-slack-sdk#857 created to see if there is a supported approach to this

Edit: they say it should be done at the app level

@LanceSandino
Copy link

I know this is probably late.... but they did it here https://jonstacks.com/2019/07/06/customizing-cloud-build-notifications

It's similar to what I do to disable slack notifications for apps that we don't want it for.

You can just check if the substitute is there, and then use that value to override the value you set in index.js

@naseemkullah
Copy link
Contributor Author

naseemkullah commented Dec 12, 2019

Better late than never :)
Thanks for sharing @LanceSandino ! So, something like (taken from article but modified to suit this issue's request):

  if (build.substitutions.hasOwnProperty('_SLACK_WEBHOOK_URL')) {
    console.log(`Build(id=${build.id}) contains a specific slack webhook URL, overriding the default webhook url...`);
  }

Is that right?

@LanceSandino
Copy link

LanceSandino commented Dec 12, 2019

Exactly.... it would check if your cloudbuild.yaml has that substitution and then if it does, do whatever you want, which would be override the slack URL.

I do something similar here:


  // don't send slack messages if we have _DISABLE_SLACK in 'cloudbuild.yaml' file -- any value is accepted
  // this is a replacement of 'ignore specific branches'
  if (build.substitutions.hasOwnProperty('_DISABLE_SLACK')) {
    if (build.substitutions['_DISABLE_SLACK']) {
      return;
    }
  }


  // ignore these repos and don't send slack message
  const ignoredRepos = ['repo', 'repo2'];
  if (ignoredRepos.includes(build.substitutions.REPO_NAME)) {
    return;
  }

@naseemkullah
Copy link
Contributor Author

naseemkullah commented Dec 12, 2019

That's great!
Provided we get @Philmod 's blessing, why not hereby join efforts in providing this flexibility?

If all parties agree,

'_SLACK_WEBHOOK_URL_OVERRIDE'
'_DISABLE_SLACK_WEBHOOK'

would be slightly better names for these looked-for build substitutions IMHO.

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

3 participants