This Is How I Built a Self-Healing CI Pipeline With Agents!

This Is How I Built a Self-Healing CI Pipeline With Agents!
View on original source
Category: SciTech
Share
Archive
Like
TL;DR: A failed CI build is often not just a failed CI build. It is a developer opening logs, scrolling through noise, trying to work out whether the problem came from their code, a flaky test, or a platform issue. A self-healing CI pipeline does not mean an AI system should automatically change production code every time a test fails. It means the pipeline should be able to detect a failure, gather the right context, identify a likely root cause and owner, notify the right person, and confirm when the pipeline is healthy again. The important idea is simple: do not make every developer become a CI detective before they can continue working. This workflow uses a three-step architecture: Build a context lake for CI runs, services, ownership, and team rules. Trigger an event-driven workflow that triages failures with AI. Close the loop by confirming that the pipeline has recovered. In the example below, the AI provides the diagnosis, but a developer still fixes the failed pipeline. That human gate is intentional. It keeps automation useful without allowing the system to make changes it has not been authorized to make. Key Takeaways Self-healing CI starts with context about builds, services, ownership, and escalation rules. AI triage should identify a likely root cause, owner, and next action immediately after failure. A human gate can preserve safety while still eliminating repetitive CI investigation work. Recovery notifications should confirm a passing CI result instead of assuming an attempted fix worked. Why CI failures quietly waste so much engineering time Most teams know the familiar loop. A developer pushes code. The CI pipeline starts. A few minutes later, the build fails. Then comes the investigation: Is this a bug in the latest change? Is the test itself flaky? Did a dependency, runner, environment, or platform service fail? Should the build simply be rerun? Who actually owns the service or infrastructure involved? None of those questions are unreasonable. The problem is repetition. A single investigation might take 20 or 30 minutes. Across multiple failed builds, developers, repositories, and weeks, that becomes a lot of lost time. The work is also disruptive. Even when the fix is small, the person responding has to switch context, search through logs, reconstruct what happened, and determine whether the failure is theirs to solve. A better pipeline does not only report that something failed. It gives the team an immediate starting point: what failed, where it happened, why it likely failed, whether it looks like a developer or platform issue, and who should investigate. The three-step framework The architecture can look complicated when it is described as 'agentic CI' or 'self-healing automation.' But it becomes much easier to understand when each piece has one responsibility. 1. Build the context lake An AI workflow can only make useful decisions if it has useful context. In this case, the context layer holds information about CI runs, repositories, services, ownership, and the rules that define a developer issue versus a platform issue. For a failed build, that may include: The repository, branch, workflow, and failed job. Relevant build output and error information. Which service or team owns the affected component. Rules for classifying infrastructure problems and code problems. Past AI invocations or workflow activity related to the run. This is the part that prevents the agent from treating every failure as an isolated block of log text. It gives the workflow a picture of the engineering environment around that failure. In the implementation shown here, Port's agentic SDLC platform acts as both the context layer and the place where the workflows are built and operated. 2. Create automation that reacts immediately The second step is event-driven automation. When a CI run fails, a workflow starts without waiting for someone to manually inspect the build. The workflow needs to do three things: Receive the failed CI event through a webhook or trigger. Send the relevant build context to an AI triage step. Route the result to the team through a Slack notification. The AI is not there to produce a vague summary like 'tests failed.' It should produce something operationally useful: a likely root cause, the relevant repository and branch, a recommended next step, and an owner. That changes the notification from a generic alarm into a focused handoff. 3. Close the loop after recovery Failure alerts are only half of the workflow. A team also needs to know when the situation is resolved. Once a new CI run passes, a recovery workflow detects that state and sends a confirmation message. This matters because otherwise someone still has to reopen the CI page, check whether the build is green, and tell everyone else that the problem is over. Closing the loop turns the process into a complete operational cycle: The key word here is confirmed. A workflow should not claim the pipeline has recovered just because someone attempted a fix. It should wait for the actual CI result. What the self-healing CI workflow looks like The example uses two separate workflows: Self-Healing CI Pipeline: runs when a CI build fails, sends the failure context to AI, and posts the triage result to Slack. CI Pipeline Recovered: runs when the pipeline succeeds again and sends the recovery notification. This separation is useful because failure handling and recovery handling have different triggers and different outcomes. One explains what needs attention. The other confirms that attention worked. The failure workflow begins with a CI event. It then moves through a webhook trigger, an AI prompt step, and another webhook that delivers the result to Slack. The recovery workflow is even simpler. It evaluates whether the CI pipeline is fixed, then triggers a Slack notification when the condition is met. That is worth emphasizing because it is easy to overbuild these systems. The first useful version does not need to solve every possible incident. It needs a trustworthy trigger, enough context for triage, a clear destination for notifications, and a reliable recovery signal. A simple example: intentionally failing a CI job To demonstrate the workflow, the example uses a small Flask application hosted in GitHub. The CI configuration contains an exit code that normally allows the job to pass: exit 0 Enter fullscreen mode Exit fullscreen mode To intentionally create a CI failure, that value is changed to: exit 1 Enter fullscreen mode Exit fullscreen mode After the change is committed, the CI build fails. That failure triggers the self-healing workflow automatically. The AI triage result identifies the repository, workflow, branch, and job. More importantly, it identifies the likely root cause: the commit intentionally set the exit code to 1, causing the test run to fail. It recommends fixing the failing tests or correcting the configuration, and assigns the issue to the relevant owner. This is where the workflow saves time. The developer does not begin with an empty search through logs. They receive the initial investigation with the failure report. In this particular example, the system deliberately keeps a human gate. The developer reviews the diagnosis, changes exit 1 back to exit 0 , and commits the correction. That distinction is important. 'Self-healing' does not have to mean 'fully autonomous code changes.' It can mean that the system heals the operational process around failures: detection, triage, ownership, notification, and recovery verification. Why the human gate is a good design choice It can be tempting to make the AI agent fix every issue automatically. In some low-risk situations, that may be appropriate. But a failed CI pipeline can be caused by more than a small configuration mistake. It could involve: A real regression in application code. An incomplete or misleading test failure. A flaky dependency or external service. A change that affects multiple services. A security-sensitive configuration issue. A platform problem that needs escalation rather than a code change. For those cases, automatic modification can create a second problem while attempting to resolve the first one. The human gate preserves accountability. The AI gathers context, identifies likely causes, and reduces the amount of detective work. The developer still evaluates the recommended action and makes the change locally. This is often the practical place to start. First, automate the work around the decision. Later, if a team has highly repetitive and low-risk fixes, it can define narrow automation boundaries for those specific cases. What the recovery message should communicate After the developer corrects the CI configuration and the next run passes, the recovery workflow sends a new Slack message. The notification confirms that the pipeline is green again and includes the relevant repository and branch details. A recovery message should make three things clear: Status: the CI pipeline is now passing. Scope: which repository, workflow, and branch recovered. Context: what failure was resolved, when that information is available. That final confirmation is small, but it removes a surprising amount of uncertainty. Nobody needs to keep checking the status page or ask whether the fix worked. The pipeline itself becomes the source of truth. How to build a useful first version If you are building this type of automation for the first time, keep the first version narrow. Choose one CI workflow, one notification channel, and one kind of failure event. A practical implementation sequence looks like this: Define the trigger. Start the workflow when a CI run fails. Collect context. Include the repository, branch, job, error output, and ownership information. Define triage rules. Tell the AI what a developer issue and a platform issue look like for your team. Require structured output. Ask for root cause, confidence, owner, and next step rather than an open-ended explanation. Send the result to Slack. Make the message actionable and easy to scan. Keep a human approval point. Let a developer make the repair until automated remediations are proven safe. Create the recovery workflow. Trigger it only from a passing CI result. It is also important to review the quality of the AI triage over time. The workflow should not be treated as correct just because it produces an answer. Check whether its root-cause summaries are useful, whether owners are assigned accurately, and whether platform failures are being distinguished from code failures in a way that matches real team responsibilities. The real goal is less firefighting The most useful outcome is not an impressive AI demo. It is a calmer engineering workflow. A good self-healing CI pipeline reduces the time between 'the build failed' and 'the right person knows what to do.' It gives teams a record of what happened, creates a clear handoff, and verifies that the incident is actually over. That is the bigger shift: moving from reactive log-scrolling to proactive pipeline operations. You do not have to begin with an agent that changes code automatically. Start with context, triage, routing, and recovery confirmation. Once those pieces are reliable, the CI pipeline is already doing far more than reporting red or green. A good pipeline does not only fail loudly. It helps the team understand the failure, act on it, and know when it is fixed.

(0)Comments

 

A note on cookies

Newshunt uses essential cookies to keep you signed in and to remember your language and country, so the site works the way you expect. With your permission, we'd also like to use analytics cookies to understand how people use Newshunt and improve it over time.

Accepting only affects analytics. To learn more, view our Privacy Policy or Terms & Conditions.