Post CircleCI pipeline failures to a Rocket.Chat channel
A CircleCI + Rocket.Chat agent flow
Is main green right now? On most teams the honest answer is whoever last looked. This flow keeps that answer in a Rocket.Chat channel instead of in someone's memory. The agent checks the latest pipeline for a branch with get_latest_pipeline_status, and when the status comes back failed it posts to a self-hosted Rocket.Chat channel with send_message, naming the project, the branch, and linking the pipeline. CircleCI reports status on request, so the agent polls on a short loop, compares against the last status it saw, and posts only when the branch flips from passing to failing, or recovers.
The flow
get_latest_pipeline_statusGets the status of the latest pipeline for a branch.
send_messageSend a message to a channel.
Step by step
- Pick the branch and the channel
Tell the agent the CircleCI project slug and the branch to watch, usually main, and the Rocket.Chat channel to post into.
- Check the latest pipeline
The agent calls get_latest_pipeline_status for the branch and reads whether the most recent pipeline succeeded, failed, or is still running.
- Post on a state change
Hold the last status. When the branch goes from green to failed the agent calls send_message with the project, branch, and pipeline link; when it recovers, it posts an all-clear.
Tell your agent
Every two minutes, get the latest CircleCI pipeline status for acme/web on the main branch. If it changed to failed since the last check, post to the Rocket.Chat channel 'build-status' with the project, branch, and pipeline link. Post an all-clear when it goes back to passing, and stay quiet while the status is unchanged.
Setup
This flow needs both servers connected to your agent. Follow each install guide:
Worth knowing
- get_latest_pipeline_status reports the latest pipeline only. If you watch several branches, the agent calls it per branch and tracks each branch's state separately.
- A pipeline can be in a running state when the agent polls. Treat running as 'no change yet' rather than a failure, or the agent posts before the result is known.
- send_message posts by channel name or ID depending on your Rocket.Chat setup. Confirm the bot account is a member of the channel, or the post is rejected.
Questions
- Can it tell me which job failed?
- The status read gives you the pipeline result. For the failing step, the agent follows up with get_build_failure_logs, which returns the failure logs it can summarize into the message.
- Does it post on every run or only on changes?
- On changes, if you track state. Have the agent remember the last status per branch and post only on a transition, so a branch that stays red doesn't repeat the same alert.