# Slack Notifications for main branch only

**URL:** <https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603>\
**Category:** Pipeline Workflows\
**Created:** [August 5, 2021, 1:12pm UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603 "2021-08-05T13:12:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbeatty](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@sbeatty](https://community.codefresh.io/u/sbeatty)\
**Post date:** [August 5, 2021, 1:12pm UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603/1 "2021-08-05T13:12:52Z")

</div>

Hi

I am trying to ensure that if our build fails we get notified by slack BUT only for our main branch.  
Here is our code for the slack notification:

```auto
hooks:
  on_fail:
    steps:
      notify:
        image: codefresh/slacknotifier
        environment:
          - SLACK_HOOK_URL=<webhook url>
          - SLACK_ATTACHMENTS=<slack message>
      when:
        branch:
          only:
            - /^(main)/i

```

At the minute it is still slacking for feature branches. Any assistance would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [August 6, 2021, 11:53am UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603/2 "2021-08-06T11:53:18Z")

</div>

Hello

I am not sure if that the regex is correct. Can you please try `/^((main)$).*/g ` or maybe just `main` on its own?

Do you have other branches that contain the word main?

---

<div class="post-metadata">

**Author:** ![sbeatty](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@sbeatty](https://community.codefresh.io/u/sbeatty)\
**Post date:** [August 9, 2021, 1:19pm UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603/3 "2021-08-09T13:19:50Z")

</div>

Hi

This is the whole thing. I only shared a snippet.

- /^(main|release.\*[0-9]+.[0-9]+)/i

---

<div class="post-metadata">

**Author:** ![Kostis](https://sea1.discourse-cdn.com/flex019/user_avatar/community.codefresh.io/kostis/32/391_2.png) [@Kostis](https://community.codefresh.io/u/Kostis)\
**Post date:** [August 9, 2021, 1:49pm UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603/4 "2021-08-09T13:49:46Z")

</div>

Hello

I don’t see any obvious problem with the regex.

Please open an issue with us (from the top right menu in the Codefresh UI) and our support team will investigate. Remember to include the URL of a build that has the issue.

---

<div class="post-metadata">

**Author:** ![sbeatty](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@sbeatty](https://community.codefresh.io/u/sbeatty)\
**Post date:** [August 9, 2021, 2:56pm UTC](https://community.codefresh.io/t/slack-notifications-for-main-branch-only/603/5 "2021-08-09T14:56:23Z")

</div>

No problem thank you
