Instantly Notify Your Slack Deployment Channel on Every GitLab Commit
Automatically sends a formatted Slack message to your deployment channel whenever a new commit is pushed to a GitLab repository. Keeps your team instantly informed without manually checking GitLab.
- 1
Create a GitLab Webhook Trigger
Add a
GitLab Triggernode to your workflow. In the node settings, copy the generated webhook URL and paste it into your GitLab project under Settings > Webhooks. Enable thePush eventsoption in GitLab. Set theEventsfield in the node toPush Hookso it fires on every commit push. - 2
Extract Key Commit Data with a Set Node
Add a
Setnode after the trigger. Create four fields:committermapped to{{ $json.commits[0].author.name }},branchmapped to{{ $json.ref.replace('refs/heads/', '') }},messagemapped to{{ $json.commits[0].message }}, andcommitUrlmapped to{{ $json.commits[0].url }}. This cleans up the data before sending it to Slack. - 3
Filter Out Non-Deployment Branches (Optional)
Add an
IFnode to only forward commits from your main deployment branches. Set the condition to check if{{ $json.branch }}equalsmainorproduction. Connect thetrueoutput to the next step. Connect thefalseoutput to aNo Operationnode if you want to silently drop other branches. - 4
Send a Formatted Message to Slack
Add a
Slacknode and connect your Slack credential. SetResourcetoMessageandOperationtoPost. In theChannelfield enter your deployment channel name such as#deployments. Set theTextfield to*New commit on {{ $json.branch }}* by {{ $json.committer }} > {{ $json.message }} <{{ $json.commitUrl }}|View Commit>. This renders a clean, readable notification in Slack.
Frequently asked questions
How do I connect my Slack account to n8n?
In the Slack node, click the `Credential` dropdown and select `Create New`. You can authenticate via OAuth2 by following the prompts, or create a Slack App with a Bot Token and paste the token into n8n. Make sure the bot is invited to your deployment channel before testing.
What if I want notifications for all branches, not just main?
Simply delete or bypass the IF node in step 3 and connect the Set node directly to the Slack node. Every push to any branch in that GitLab project will then trigger a Slack notification.
Can I include multiple commits in one notification if several are pushed at once?
The current recipe uses `$json.commits[0]` which reads only the latest commit. To list all commits you would need a more advanced setup with a loop node, but for most teams showing the latest commit per push is sufficient and keeps messages concise.