Post to Slack
A composite action that posts a message to a Slack channel via an incoming webhook. It runs inline in the calling job, so a notification adds a single step — no separate run or runner. The webhook URL is sensitive — store it in H2O Secure Store and pass it in as a secret input (secret: true), so the value is redacted from logs.
Action
id: notify-slack
name: Post Message to Slack
inputs:
webhook_url:
type: string
required: true
secret: true
description: "Slack incoming webhook URL"
message:
type: string
required: true
description: "Message text to post"
channel:
type: string
default: ""
description: "Override channel (optional, uses webhook default if empty)"
username:
type: string
default: "H2O Workflows"
description: "Bot username displayed in Slack"
steps:
- name: "Send Slack notification"
timeout: "1m"
env:
WEBHOOK_URL: "${{ .inputs.webhook_url }}"
MESSAGE: "${{ .inputs.message }}"
CHANNEL: "${{ .inputs.channel }}"
USERNAME: "${{ .inputs.username }}"
run: |
python3 -c "
import os, json, urllib.request
payload = {
'text': os.environ['MESSAGE'],
'username': os.environ['USERNAME'],
}
if os.environ.get('CHANNEL'):
payload['channel'] = os.environ['CHANNEL']
req = urllib.request.Request(
os.environ['WEBHOOK_URL'],
data=json.dumps(payload).encode(),
headers={'Content-Type': 'application/json'},
)
resp = urllib.request.urlopen(req)
print(f'Slack response: {resp.status} {resp.read().decode()}')
"
Publish the action to make it callable from workflows.
Use it from your workflow
Reference your stored secret with ${{ .secrets.<name> }} and pass it to the action via with:
id: train-and-notify
name: Train and Notify
secrets:
- name: workspaces/<workspace-id>/secrets/slack-webhook
as: slack_webhook
jobs:
train:
steps:
- name: Train model
run: python train.py
- uses: <workspace-id>:notify-slack@latest
with:
webhook_url: "${{ .secrets.slack_webhook }}"
message: "Training finished successfully"
Alert on failure
Because the action runs inline as a step, it combines with an if condition to notify only when an earlier step failed:
- uses: <workspace-id>:notify-slack@latest
if: failure()
with:
webhook_url: "${{ .secrets.slack_webhook }}"
message: "Training FAILED — check the run logs"
Feedback
- Submit and view feedback for this page
- Send feedback about H2O Workflows to cloud-feedback@h2o.ai