I have two slack channels: Team A and Team B.
I have one Gitlab repository with two branches: Branch A and Branch B.
I want to set up two webhooks: When a push occurs on Branch A, a message is sent on Slack channel Team A. When a push occurs on Branch B, a message is sent on Slack channel Team B.
I think we cannot use Gitlab's Webhooks section and we have to use Slack Integration section as discribed in this Stack Overflow question.
On Gitlab's Slack Integragtion I can only enter one url for one of the slack channels but not 2:
Does anyone know a workaround ?
I don't think there is a workaround using only webhook, which is why Akshay Kapoor wrote an alternative solution "Custom Slack Integrations for Gitlab CI/CD Pipelines"
The idea is to use the GitLab CI/CD feature (builds on the GitLab server side, as opposed to WebHooks which are sending events on the client side)
The end result:
The idea is that, on the script run on the server side, you can control and add any condition you want (like the branch being pushed) in order to redirect your Slack notification.
Akshay uses Slack Block Kit (and its playground) in order to build its notification message.
And then he posts it:
function share_slack_update() {
curl -X POST \
--data-urlencode "payload=$(print_slack_summary)" \
"${SLACK_WEBHOOK}"
}