Skip to main content

Build status notification

Summarize a build with a plain-text notification fallback, status fields and contextual detail.

Output

Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.

✅ example build passed

Branch main
Commit abc1234
Author Nick
Duration 3m 12s

📅 Triggered by push to main
Serialized output
{
"channel": "C1",
"mrkdwn": true,
"blocks": [
{
"type": "header",
"block_id": "<generated-block-id>",
"text": {
"type": "plain_text",
"text": ":white_check_mark: example build passed"
}
},
{
"type": "section",
"block_id": "<generated-block-id>",
"fields": [
{
"type": "mrkdwn",
"text": "*Branch*\n`main`"
},
{
"type": "mrkdwn",
"text": "*Commit*\n`abc1234`"
},
{
"type": "mrkdwn",
"text": "*Author*\nNick"
},
{
"type": "mrkdwn",
"text": "*Duration*\n3m 12s"
}
]
},
{
"type": "divider",
"block_id": "<generated-block-id>"
},
{
"type": "context",
"block_id": "<generated-block-id>",
"elements": [
{
"type": "mrkdwn",
"text": ":calendar: Triggered by push to `main`"
}
]
}
],
"text": "Build passed for example@main"
}

Code​

A CI notification with summary fields and a contextual footer.

from slackblocks import (
ContextBlock,
DividerBlock,
HeaderBlock,
Message,
SectionBlock,
Text,
)


def build_status_message(
*,
channel: str,
project: str,
branch: str,
commit: str,
author: str,
duration: str,
passed: bool,
) -> Message:
icon = ":white_check_mark:" if passed else ":x:"
status = "passed" if passed else "failed"

return Message(
channel=channel,
text=f"Build {status} for {project}@{branch}", # plain-text fallback
blocks=[
HeaderBlock(f"{icon} {project} build {status}"),
SectionBlock(
fields=[
f"*Branch*\n`{branch}`",
f"*Commit*\n`{commit[:7]}`",
f"*Author*\n{author}",
f"*Duration*\n{duration}",
],
),
DividerBlock(),
ContextBlock(
elements=[
Text(f":calendar: Triggered by push to `{branch}`"),
],
),
],
)
print(build_status_message(channel="C1", project="example", branch="main", commit="abc1234", author="Nick", duration="3m 12s", passed=True).json())

Tips:

  • Always pass a text= fallback to Message — Slack uses it for desktop and mobile push notifications.
  • SectionBlock accepts up to 10 fields, each up to 2,000 characters.