Action designed for posting Slack messages via an incoming webhook to denote the start and/or end of a Workflow run and the overall status.
Offers a minimal and opinionated output, but with the ability to append custom fields (such as build output URLs or generated file sizes) onto messages.
Single job workflow:
jobs:
main:
name: Single job
runs-on: ubuntu-latest
steps:
- name: Slack message start
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
webhook-url: https://hooks.slack.com/services/...
- name: Checkout source
uses: actions/checkout@v3
# -- insert job steps here --
- name: Slack message finish
if: always()
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
result: ${{ job.status }} # final result of job
webhook-url: https://hooks.slack.com/services/...
Multiple job workflow:
jobs:
slack-message-start:
name: Slack message start
runs-on: ubuntu-latest
steps:
- name: Slack message
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
webhook-url: https://hooks.slack.com/services/...
first:
name: First job
runs-on: ubuntu-latest
steps:
# -- insert job steps here --
second:
name: Second job
runs-on: ubuntu-latest
steps:
# -- insert job steps here --
nth-job:
name: nth job
runs-on: ubuntu-latest
steps:
# -- insert job steps here --
slack-message-finish:
name: Slack message finish
if: always()
needs:
# note: list *all* jobs defined above
- slack-message-start
- first
- second
- nth-job
runs-on: ubuntu-latest
steps:
- name: Slack message
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
result: ${{ join(needs.*.result,'|') }} # final results of all jobs
webhook-url: https://hooks.slack.com/services/...
Message only for workflow cancelled or failure with specific branch:
jobs:
main:
name: Message on job failure
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
# -- insert job steps here --
- name: Slack message failure
if: (cancelled() || failure()) && (github.ref == 'refs/heads/main')
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
result: ${{ job.status }} # final result of job
webhook-url: https://hooks.slack.com/services/...
Custom fields can be appended to the resulting Slack message via the field-list:
input property:
jobs:
main:
name: Single job
runs-on: ubuntu-latest
steps:
# -- insert job steps here --
- name: Slack message finish
if: always()
uses: magnetikonline/action-slack-workflow-start-finish@v2
with:
channel: '#target-channel'
field-list: |
Total file size|${{ property.size.value }}KB
Preview deployed website|<https://hostname.com/preview/...|Click here>
result: ${{ job.status }}
webhook-url: https://hooks.slack.com/services/...
The following rules are used to determine the eventual status of a workflow run:
- If all jobs succeed:
success
.- Note: Skipped jobs are still considered:
success
.
- Note: Skipped jobs are still considered:
- If one or more jobs cancelled:
cancelled
- unless... - If any job fails, overall workflow:
failure
.