CircleCI-Public / slack-orb

Create custom Slack notifications for CircleCI job statuses
https://circleci.com/developer/orbs/orb/circleci/slack
MIT License
212 stars 205 forks source link

Not possible to avoid running on branches #415

Open goetzc opened 1 year ago

goetzc commented 1 year ago

Orb version: 4.12.5

What happened:

I want to avoid sending the notification on any branch trigger, including the default main branch. Only want to send notifications on workflows triggered by tags. So I have set branch_pattern and tag_pattern to different values without success.

branch_pattern: ''
# or
branch_pattern: ' '
# or
branch_pattern: '.'
# or
branch_pattern: '(?!)'

Or according to the README https://github.com/CircleCI-Public/slack-orb/blob/3e43e753919b007d681cb2a16b37cabe5a8eda83/README.md?plain=1#L61

Keep in mind that "branch_pattern" and "tag_pattern" are mutually exclusive.

but it seems outdated as it's not working with:

tag_pattern: '.+'

Without any pattern (or using the tag_pattern) it send the notification. On any of the branch_pattern above, it fails with the following error:

NO SLACK ALERT

Current reference "main" does not match any matching parameter
Current matching pattern: .

Exited with code exit status 1

CircleCI received exit code 1

image image

Which makes the whole job fail.

Expected behavior:

I expect it to avoid sending the notification on any branch (including the default branch), and exiting cleanly with code 0, so the whole workflow/job passes.

Additional Information:

I'm not sure if I'm missing something, as the normal job filters (filters.tags.only, filters.branches.only or filters.branches.ignore) work normally. Is there some special pattern to avoid sending the notification on any branch?

Thanks

EricRibeiro commented 8 months ago

Hey @goetzc 👋

Thank you for bringing this to our notice, and sorry for not getting to it sooner. We have a proof-of-concept Slack orb wholly written in Go that will potentially solve this pattern-matching issue and some others.

Would you all be open to trying it and seeing if it solves your problem? We are looking for some early feedback. All you have to do is replace the orb version 4.12.5 in your config with dev:4463bcaee946c1e91829fdf6b3e0d1a7b6f12210:

version: 2.1

orbs:
-  slack: circleci/slack@4.12.5
+  slack: circleci/slack@dev:4463bcaee946c1e91829fdf6b3e0d1a7b6f12210

Please remember that dev:4463bcaee946c1e91829fdf6b3e0d1a7b6f12210 is a proof-of-concept, so it doesn't have feature parity with v4.12.5. As of the time of this writing, it doesn't support sub-shells expansions inside the templates:

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "$(cat /tmp/msg)"
            }
        }
    ]
}

Thanks in advance, and let us know if it works for you! 🙇

Warning dev:4463bcaee946c1e91829fdf6b3e0d1a7b6f12210 will be deleted after 90 days (January 22, 2024). Remember to roll back to a production version before the developer version gets deleted.