CircleCI-Public/slack-orb

Not possible to avoid running on branches

Closed this issue · 4 comments

goetzc commented

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

A comma separated list of regex matchable branch or tag names. Notifications will only be sent if sent from a job from these branches/tags. By default ".+" will be used to match all branches/tags. Pattern must match the full string, no partial matches. Keep in mind that "branch_pattern" and "tag_pattern" are mutually exclusive.

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

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.

@goetzc The development of the go version of the orb is on stand by for now. I'm checking this issue to see if there's a way you can implement it or if we need to do a change on the pattern logic.
For now, is it possible for your use case to use the normal job filters? More information here

@goetzc You explained two problems, the pattern not working and the exit 1.
The first, you are using login shell. That's the cause of the exit 1 error. This shouldn't happen in the last version of the orb, as it is using a default shell configuration.
The second I'm fixing in PR #459, this should be fixed in our next release.

Version 4.14.0 is solving the issue with tag pattern.