Published

Jenkins CI/CD for LLM Applications: Prompt Tests, Eval Gates and Safe Rollouts

Jenkins CI/CD for LLM applications: version prompts in Git, run eval gates in a Declarative Pipeline, handle secrets, approve risky changes and roll back.

Written by
Ali ÖzdurmuşFounder, Veni AI
Reading time
8 min read
A developer at a desk at night with several monitors showing code.

An AI app can break without a single line of code changing. Someone edits a prompt, a provider retires a model version, a retrieval setting moves, and answers quietly get worse. Jenkins CI/CD for LLM applications treats those changes like code: versioned in Git, tested on every change and blocked from release when quality drops.

If your company already runs Jenkins, you do not need a new platform. You need a pipeline that knows what "worse" means for an AI system.

What Changes When the Artifact Is a Prompt

A normal build is deterministic: same input, same result. An LLM call is not. The pipeline therefore needs three things beyond compile-and-test:

  • Everything that shapes behavior lives in Git: prompts, model ids, temperature, tool definitions, retrieval settings, and the evaluation test set.
  • Quality is a number: an eval score computed on a fixed test set, compared against the last release.
  • Cost is a budget: every test calls a paid API, so the pipeline decides how much to run and when.

This is the delivery side of the evaluation ideas in our AI governance guide, where a release gate blocks a change that scores below a threshold. Here the gate runs inside Jenkins.

Repository Layout

prompts/            # versioned prompt templates
config/model.yaml   # model id, temperature, tools, retrieval settings
tests/unit/         # normal code tests, no model calls
evals/cases.jsonl   # fixed test set with expected outputs
evals/baseline.json # score of the last released version
evals/run_eval.py   # runs the suite, writes results.xml and score.json
evals/gate.py       # compares score with the baseline
Jenkinsfile

Keep config/model.yaml pinned to an explicit version, for example provider/model-id@version. A moving alias turns every provider update into an untracked release.

The Jenkinsfile

This Declarative Pipeline runs a cheap sampled suite on pull requests and the full suite on main and nightly.

groovy
pipeline {
    agent any

    options {
        timeout(time: 45, unit: 'MINUTES')
        disableConcurrentBuilds()
        buildDiscarder(logRotator(numToKeepStr: '30'))
    }

    triggers {
        cron('H 2 * * *') // nightly full evaluation
    }

    environment {
        EVAL_SAMPLE = "${env.CHANGE_ID ? '0.2' : '1.0'}" // 20% on PRs, full otherwise
    }

    stages {
        stage('Unit tests') {
            steps {
                sh 'pip install -r requirements.txt'
                sh 'pytest tests/unit'
            }
        }

        stage('Prompt regression and eval') {
            steps {
                withCredentials([string(credentialsId: 'llm-api-key', variable: 'LLM_API_KEY')]) {
                    sh 'python evals/run_eval.py --sample "$EVAL_SAMPLE" --out evals/out'
                }
            }
            post {
                always {
                    junit testResults: 'evals/out/results.xml', allowEmptyResults: false
                    archiveArtifacts artifacts: 'evals/out/**', fingerprint: true
                }
            }
        }

        stage('Quality gate') {
            steps {
                sh 'python evals/gate.py evals/out/score.json evals/baseline.json'
            }
        }

        stage('Approve high-risk change') {
            when {
                beforeInput true // check the branch before asking, so PR builds never wait for approval
                branch 'main'
            }
            input {
                message 'Model or prompt change for a high-risk workflow. Deploy?'
                ok 'Deploy'
                submitter 'ai-leads'
            }
            steps {
                echo 'Approved'
            }
        }

        stage('Deploy canary') {
            when { branch 'main' }
            steps {
                sh './deploy.sh --env production --traffic 10'
            }
        }
    }

    post {
        failure {
            echo 'Build failed. See archived eval results.'
        }
    }
}

A few details worth knowing, all from the Jenkins Pipeline documentation (opens in a new tab):

  • junit marks a build unstable, not failed, when tests fail. That is why the quality gate is a separate stage whose non-zero exit code fails the build.
  • withCredentials keeps the API key out of the Jenkinsfile and masks it in the console log. Never echo it and never pass it as a command-line argument.
  • The input directive pauses the stage and restricts who can approve with submitter. Put it before the deploy so a human decision happens before production changes.
  • cron with the H symbol spreads scheduled jobs so they do not all start at the same minute.

The Eval Gate

The gate is a small script, deliberately boring. It fails the build when the score drops below the last release by more than an agreed tolerance.

python
import json
import sys

TOLERANCE = 0.01  # allow 1 point of noise

def main(score_path: str, baseline_path: str) -> int:
    score = json.load(open(score_path))["score"]
    baseline = json.load(open(baseline_path))["score"]
    print(f"score={score:.3f} baseline={baseline:.3f}")
    if score < baseline - TOLERANCE:
        print("Quality gate failed: score dropped below the last release.")
        return 1
    return 0

if __name__ == "__main__":
    sys.exit(main(sys.argv[1], sys.argv[2]))

Model output varies between runs, so a tolerance, a fixed temperature and a large enough test set matter. On a sampled PR run, treat a small drop as a warning and let the full run on main decide. When a release succeeds, update evals/baseline.json in the same commit that tags it.

Publishing Eval Results

Have run_eval.py write one JUnit test case per eval case, with the metric, the expected value and the model output in the failure message. Jenkins then shows trends, failed cases and history for free, and archiveArtifacts keeps the raw outputs so a reviewer can see exactly what the model said. These files are also the evidence trail an auditor asks for.

Controlling Cost and Rate Limits in CI

TechniqueEffect
Sample the test set on pull requestsA fast, cheap signal for every change
Full suite on main and nightlyComplete coverage where it matters
Cache responses by hash of prompt, model and inputUnchanged cases cost nothing
Limit concurrency and retry with backoffStays inside provider rate limits
Use a separate CI API key with a spending capA runaway job cannot drain the budget
Cheaper model for smoke tests, pinned model for the gateSpeed without weakening the gate

See our LLM cost optimization guide for production-side savings, and LLM API integration best practices for retries and timeouts.

Staged Rollout and Rollback

Deploy in steps: a canary with a small share of traffic, then the rest once error rate, latency and a sampled quality check look healthy. Rollback must be one command, because the prompt and model config are versioned files: redeploy the previous Git tag. Keep the previous version deployable for as long as the new one is on trial. The infrastructure side is covered in AI model deployment with Kubernetes and MLOps.

Which Changes Need a Human

ChangeGate
Prompt wording in a low-risk workflowAutomated eval gate
New model version or providerEval gate plus manual input approval
Tool or permission changes for an agentEval gate plus approval from the workflow owner
Anything touching payments, health or employment decisionsApproval, legal review and a full audit trail

Using an AI Agent to Triage Failed Builds

A failed build often costs more in reading than in fixing. An AI agent can take the first pass: read the console log, group the failure (flaky network, dependency problem, real regression, eval drop), suggest the likely cause, and post it as a pull request comment or open a ticket with the relevant log lines.

Keep it advisory. The agent gets read-only access to logs and artifacts, no deploy rights and no ability to approve its own suggestions. A human decides what to do. Log the agent's output next to the build so you can check later how often it was right.

FAQ

Can Jenkins run LLM evaluations? Yes. Jenkins runs any script, so an eval runner in Python can execute inside a pipeline stage, write JUnit XML for the junit step and fail the build through its exit code.

How do I stop the pipeline from costing too much? Sample the test set on pull requests, run the full suite on main and nightly, cache identical calls and use a capped CI key.

How do I handle non-deterministic output? Fix temperature, use a test set large enough to smooth noise, and set a small tolerance in the gate rather than demanding an exact match.

Quick Start

  1. Move prompts and model config into Git and pin the model version.
  2. Build a test set of 100 to 300 real, anonymized cases with expected outputs.
  3. Write the eval runner and the gate script, and record a baseline score.
  4. Add the stages to your Jenkinsfile with withCredentials for the API key.
  5. Run sampled evals on pull requests and the full suite on main and nightly.
  6. Add an input approval and a canary deploy for high-risk changes.
  7. Practice the rollback before you need it.

Summary

Shipping an AI application is not harder than shipping code, but it needs one extra thing: a measured definition of quality that the pipeline enforces. Jenkins already provides the pieces: credentials, test reporting, approvals and scheduling.

Veni AI designs and runs this delivery pipeline as part of the AI applications we build. Explore custom AI apps, see how we run and improve them after launch, or talk to us.

Keep reading

Have a process that should run on AI?

Describe one process as it runs today, and we'll show you which repetitive steps an AI application or agent could handle.