You can notify Slack of GitHub Actions results.
This action only performs read operations. Set the minimum required permissions in your workflow:
permissions:
actions: read # to list workflow jobs
contents: read # to fetch commit metadatasteps:
- uses: step-security/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow # selectable (default: repo,commit)
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.steps:
- uses: step-security/action-slack@v3
with:
status: ${{ job.status }}
author_name: Integration Test # default: step-security@action-slack
fields: repo,commit,message,author # default: repo,commit
mention: here
if_mention: failure,cancelled
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.| Key | Value | Default |
|---|---|---|
| status | 'success' or 'failure' or 'cancelled' or 'custom' |
'' |
| fields | You can choose the items you want to add to the fields at the time of notification. | 'repo,commit' |
| text | Specify the text you want to add. All strings will be overwritten. | '' |
| author_name | It can be overwritten by specifying. The job name is recommended. | 'step-security@action-slack' |
| mention | 'here' or 'channel' or user_group_id or user_id |
'' |
| if_mention | Specify 'success' or 'failure' or 'cancelled' or 'custom' or 'always'. |
'' |
| username | Override the legacy integration's default name. | '' |
| icon_emoji | emoji code string to use in place of the default icon. | '' |
| icon_url | icon image URL string to use in place of the default icon. | '' |
| channel | Override the legacy integration's default channel. This should be an ID, such as C8UJ12P4P. |
'' |
| custom_payload | e.g. {"text": "Custom Field Check", obj: 'LOWER CASE'.toLowerCase()} |
'' |
| job_name | If you want to overwrite the job name, you must specify it. | '' |
Recommend ${{ job.status }}.
steps:
- uses: step-security/action-slack@v3
with:
status: ${{ job.status }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredsteps:
- uses: step-security/action-slack@v3
with:
text: 'any string'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredsteps:
- uses: step-security/action-slack@v3
with:
author_name: 'my workflow'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredThis can be mentioned in combination with if_mention.
steps:
- uses: step-security/action-slack@v3
with:
mention: 'here'
if_mention: failure
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredIf you want to mention multiple users in multiple cases:
steps:
- uses: step-security/action-slack@v3
with:
mention: 'user_id,user_id2'
if_mention: 'failure,cancelled'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredIf you want to mention a user group, prefix the user group id with subteam^:
steps:
- uses: step-security/action-slack@v3
with:
mention: 'subteam^S012ABC3Y4Z' # replace S012ABC3Y4Z with your user group id
if_mention: 'failure,cancelled'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredOnly legacy incoming webhook supported.
steps:
- uses: step-security/action-slack@v3
with:
username: 'my workflow bot'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredOnly legacy incoming webhook supported.
steps:
- uses: step-security/action-slack@v3
with:
icon_emoji: ':octocat:'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredOnly legacy incoming webhook supported.
steps:
- uses: step-security/action-slack@v3
with:
icon_url: 'http://example.com/hoge.png'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredOnly legacy incoming webhook supported.
steps:
- uses: step-security/action-slack@v3
with:
channel: '#general'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredsteps:
- uses: step-security/action-slack@v3
with:
status: custom
custom_payload: |
{
text: "Custom Field Check",
attachments: [{
"author_name": "step-security@action-slack", // json
fallback: 'fallback',
color: 'good',
title: 'CI Result',
text: 'Succeeded',
fields: [{
title: 'lower case',
value: 'LOWER CASE CHECK'.toLowerCase(),
short: true
},
{
title: 'reverse',
value: 'gnirts esrever'.split('').reverse().join(''),
short: true
},
{
title: 'long title1',
value: 'long value1',
short: false
}],
actions: [{
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredSee the Slack docs for custom_payload reference:
In action-slack, job information is retrieved from the job name. If you overwrite the job name, use job_name to match it.
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: step-security/action-slack@v3
with:
job_name: Test # Match the name above.
fields: job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredNote: Additional configuration is required to work with matrix builds. Don't forget to add
MATRIX_CONTEXT. Not required if the fields do not containjobortook.
steps:
- uses: step-security/action-slack@v3
with:
fields: job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
MATRIX_CONTEXT: ${{ toJson(matrix) }} # requiredIf you have more than one, enter them in CSV format. Available fields:
| Field | Environment Variable | Description |
|---|---|---|
| repo | AS_REPO |
A working repository name |
| commit | AS_COMMIT |
commit hash |
| eventName | AS_EVENT_NAME |
trigger event name |
| ref | AS_REF |
git reference |
| workflow | AS_WORKFLOW |
Generate a workflow link from git sha |
| workflowRun | AS_WORKFLOW_RUN |
Generate a link to the present workflow run |
| message | AS_MESSAGE |
commit message |
| author | AS_AUTHOR |
The author who pushed |
| job | AS_JOB |
Generate a job run link of the job that was executed |
| took | AS_TOOK |
Execution time for the job |
| pullRequest | AS_PULL_REQUEST |
Pull Request title, number with link |
steps:
- uses: step-security/action-slack@v3
with:
fields: repo,commit
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredTo include all fields, specify all:
steps:
- uses: step-security/action-slack@v3
with:
fields: all
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredIn either of the following cases, use the job_name parameter instead of MATRIX_CONTEXT:
- Job name overwritten by the
namesyntax - Using
matrixwithinclude
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, windows-latest, ubuntu-18.04]
node: [8, 10, 12, 14]
include:
- os: windows-latest
node: 8
npm: 6
steps:
- uses: step-security/action-slack@v3
with:
job_name: test (${{ matrix.os }}, ${{ matrix.node }}) # named without `npm`
fields: job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredNotify Slack of the results of a single job run.
steps:
- uses: step-security/action-slack@v3
with:
status: ${{ job.status }}
fields: repo,message,commit,author,action,eventName,ref,workflow,job,took,pullRequest
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.status: ${{ job.status }} passes the job outcome (success, failure, cancelled) to action-slack.
if: always() ensures action-slack runs even when the job fails.
For notifications in a format other than the default, use status: custom.
steps:
- uses: step-security/action-slack@v3
with:
status: custom
custom_payload: |
{
text: "Custom Field Check",
attachments: [{
"author_name": "step-security@action-slack", // json
fallback: 'fallback',
color: 'good',
title: 'CI Result',
text: 'Succeeded',
fields: [{
title: 'lower case',
value: 'LOWER CASE CHECK'.toLowerCase(),
short: true
},
{
title: 'reverse',
value: 'gnirts esrever'.split('').reverse().join(''),
short: true
},
{
title: 'long title1',
value: 'long value1',
short: false
}],
actions: [{
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # requiredJavaScript expressions are available inside custom_payload (e.g. toLowerCase()). You can also combine custom_payload with fields to access field values via environment variables:
steps:
- uses: step-security/action-slack@v3
with:
status: custom
fields: workflow,job,commit,repo,ref,author,took
custom_payload: |
{
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always() # Pick up events even if the job fails or is canceled.MIT — see LICENSE.

