TechBuzzPro

How to Integrate Slack with CircleCI: Step-by-Step

· 5 min read · Apps & Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You can integrate Slack with CircleCI in a few minutes by adding a Slack webhook URL to your CircleCI project and using either the built-in Slack orb or a simple curl command in your config. This sends build status notifications to a Slack channel so your team sees pass/fail results without checking the CircleCI dashboard. Before you start, you need a Slack workspace where you can install apps (or ask an admin), a CircleCI account with a project already building, and permission to edit the project's .circleci/config.yml file.

What You'll Need

  • A Slack workspace and a channel (e.g., #ci-builds) where notifications should appear.
  • Permission to add an app or incoming webhook to Slack. If you are not an admin, ask one to create the webhook for you.
  • A CircleCI account with at least one project that runs builds.
  • Access to the project's repository so you can edit .circleci/config.yml and push changes.
  • Optional: a Slack bot token if you prefer the Slack orb's bot-token method instead of a webhook.

Step-by-Step

  1. Create a Slack incoming webhook. In Slack, open the app directory (or go to https://api.slack.com/apps in a browser) and create a new app. Under Incoming Webhooks, activate them and click Add New Webhook to Workspace. Choose the channel you want notifications in and authorize. Copy the webhook URL — it looks like https://hooks.slack.com/services/.... Treat it like a password; anyone with it can post to that channel.
  2. Store the webhook URL as a CircleCI environment variable. In CircleCI, open your project, go to Project Settings > Environment Variables, and add a variable named SLACK_WEBHOOK with the URL as the value. Storing it here keeps it out of your repository. (Menu labels can differ slightly by CircleCI version or plan.)
  3. Choose your integration method. The simplest is to add a run step that posts a message with curl. The more maintainable option is the official CircleCI Slack orb, which handles formatting and retries. Both work; pick one.
  4. Add a notification step to your config. Open .circleci/config.yml. For the curl method, add a step like this inside your job (adjust the message):
    - run: curl -X POST -H 'Content-type: application/json' --data '{"text":"Build finished: $CIRCLE_JOB on $CIRCLE_BRANCH"}' $SLACK_WEBHOOK
    For the orb method, add orbs: slack: circleci/slack@4.12.5 (use the current version from the orb registry) at the top, then add a step such as - slack/notify: event: fail inside your job. The orb reads the webhook from the SLACK_WEBHOOK environment variable by default.
  5. Commit and push. CircleCI will pick up the change and run a new pipeline. Watch the job log to confirm the notification step succeeds.
  6. Verify in Slack. Check the channel you selected. You should see a message when the job finishes (or only on failure, depending on how you configured the step). If nothing appears, check the job log for errors from the curl command or the orb.
  7. Refine the message. Use CircleCI's built-in variables — $CIRCLE_BRANCH, $CIRCLE_JOB, $CIRCLE_BUILD_URL, $CIRCLE_PULL_REQUEST — to include useful context. The Slack orb also lets you customize the message template and choose which events (success, fail, always) trigger a notification.

Common Mistakes

  • Hardcoding the webhook URL in the config file. This exposes the secret to anyone with repo access. Always use an environment variable.
  • Using the wrong channel. The webhook is bound to the channel chosen when you created it. To post elsewhere, create a new webhook or use a bot token with chat:write scope.
  • Forgetting to escape JSON in curl. Quotes and special characters in the message can break the JSON payload. Test locally or use the orb, which handles escaping.
  • Assuming notifications fire on every branch. By default, your step runs only where you place it. If you want notifications for all branches, add the step to a job that runs on all branches or use the orb's event: always.
  • Not checking the job log. A failed curl often returns a non-zero exit code that fails the build. Inspect the log to see the HTTP response from Slack.

Tips

  • Use a dedicated channel like #ci-builds to keep noise out of general chat.
  • Notify only on failure to reduce clutter, or send a summary at the end of a workflow.
  • Pin the Slack orb version (e.g., circleci/slack@4.12.5) so future orb updates don't change behavior unexpectedly.
  • Include the build URL in the message so teammates can jump straight to the failed job.
  • Rotate the webhook URL if it is ever exposed, and remove old webhooks from Slack when no longer needed.

Troubleshooting

If no message appears, start with the job log: look for HTTP 4xx or 5xx responses from Slack. A 404 usually means the webhook URL is wrong or was revoked; a 403 means the app lacks permission to post to that channel. Recreate the webhook and update the environment variable. If the step fails the build, add || true after the curl command to prevent a notification failure from failing the pipeline (but do this only if you are comfortable missing alerts). For the orb, check that the orb version exists and that SLACK_WEBHOOK is set in the project or context. If you use contexts, ensure the context is attached to the workflow. Finally, confirm the channel still exists and the app is still installed in the workspace.

Frequently Asked Questions

Can I send notifications to multiple Slack channels?

Yes. Create a separate incoming webhook for each channel and store each URL as a different environment variable, then reference the appropriate one in your config.

Do I need a paid Slack plan?

No. Incoming webhooks and the Slack orb work on free Slack workspaces, though message history limits may apply.

Can I use Slack notifications with CircleCI's free plan?

Yes. The integration is part of your pipeline configuration and does not require a specific CircleCI plan.

What if my build fails before the notification step runs?

Place the notification step at the end of the job, or use the orb's fail event, which runs even when earlier steps fail. For workflow-level notifications, use a separate job that depends on the build job.

Is the webhook URL the same as a Slack bot token?

No. A webhook posts to one specific channel; a bot token can post to any channel the bot is invited to and supports more Slack API methods. The Slack orb supports both.

Can I customize the message format?

Yes. With curl, you control the JSON payload. With the Slack orb, you can supply a custom template or use the built-in templates and override fields like the message text and color.