Notify on failures only
Closed this issue · 9 comments
Hello! First of all, thanks a lot for this Github action, my team has been using it for quite some time and it helps us a lot in our routine.
One question: is there any config option that enables us to only notify a given Slack channel in case of a failure?
Thanks!
Ref: #61 (comment)
You can use the condition: if: failure()
- name: Slack Notification
if: failure()
uses: rtcamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
...
thx a lot!
Is it possible to place the answer to this question to README file?
Notification on failure is the most popular use case and the only way to find how to do that is to search for this issue.
@mrrobot47 going back to this topic after a few months :D how can i tag the commit author, so that people can react faster in case they break the build? i'm not sure about how to use the SLACK_LINK_NAMES
variable. would it be something like this?
- name: Notify failures
if: failure()
uses: rtCamp/action-slack-notify@v2
env:
SLACK_LINK_NAMES: true
SLACK_CHANNEL: releases
SLACK_MESSAGE: "hey @$SLACK_MSG_AUTHOR, sorry to let you know you broke the build"
@felipecao Did you ever figure out how to mention the author in the Slack message?
@sc0ttman i've finally managed to mention author on messages, i've done using a mix of Github actions environment variables and jq
First, i've set an environment variable (Github action secret) that contains a json where i map Github handles with Slack handles:
‘[{“gh_handle": "felipecao", "slack_id": "U01TC0KNKQQ"},{"gh_handle": "otheruser", "slack_id": "otherid"}]’
(make sure to keep the '
character both in the beginning and in the end, it matters)
Then I have a step on my Github workflow YAML file where I use jq
to lookup the Slack ID associated with a Github handle:
- name: Lookup Slack ID
uses: sergeysova/jq-action@v2
id: slack_id
with:
cmd: jq --raw-output '.[]| select(.gh_handle=="${{ github.actor }}") |.slack_id' <<< ${{ secrets.GH_SLACK_USERS }}
And then I finally reuse that step whenever i want to notify someone:
- name: Notify
uses: rtCamp/action-slack-notify@v2
env:
SLACK_CHANNEL: my-channel
SLACK_MESSAGE: "<@${{steps.slack_id.outputs.value}}> check out this message"
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_COLOR: ${{ job.status }}
Hope this helps you ;)