DEV Community

Cover image for How to set up Slack notifications from GitLab CI/CD using the Slack API
Cheulong Sear
Cheulong Sear

Posted on

How to set up Slack notifications from GitLab CI/CD using the Slack API

Learn how to integrate Slack with GitLab CI/CD to receive real-time build and deployment notifications directly in your Slack channels. This step-by-step guide walks you through creating a Slack app, configuring the Slack API, and setting up GitLab pipeline jobs to send custom messages for successful builds, failures, and more.

Create a Slack App

1.Go to https://api.slack.com/apps

image.png

After signin

2.Click Create New App → From Scratch

image1.png

3.Give it a name (e.g., GitLab CI Notifier)
4.Choose your workspace

image2.png

5.Create App

image3.png

You can add App Icon and App name here

image4.png

Add Incoming Webhooks

1.In the left sidebar, go to Features → Incoming Webhooks

image5.png

2.Toggle Activate Incoming Webhooks → ON

image7.png

3.Click Add New Webhook to Workspace
4.Choose a channel or private group where messages should be sent

image8.png

5.Copy the Webhook URL:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

Store the Webhook URL in GitLab

1.Go to your GitLab project → Settings → CI/CD → Variables

2.Add a variable:

image10.png

Edit your .gitlab-ci.yaml

Add a job that sends a message to Slack:

stages:
  - slack_notify

notify_slack:
  stage: slack_notify
  tags:
    - linux-homelab-general-vm
  image:
    name: alpine:latest
  before_script:
    - apk add --no-cache curl
  script:
    - |
      MESSAGE="✅ Pipeline $CI_PIPELINE_STATUS for project $CI_PROJECT_NAME on branch $CI_COMMIT_REF_NAME – $CI_COMMIT_SHORT_SHA"
      echo "Sending Slack notification: $MESSAGE"
      curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$MESSAGE\"}" "$SLACK_WEBHOOK"
  when: always
Enter fullscreen mode Exit fullscreen mode

image11.png

=== Done ===

(back to top)

Leave a comment if you have any questions.

===========

Please keep in touch

Portfolio

Linkedin

Github

Youtube

Top comments (0)