Running promptfoo in GitLab CI

Running promptfoo evals in GitLab CI means a job on the node:24 image, a cache for the promptfoo cache directory, masked provider keys and a pipeline that fails the merge request when quality drops. This page covers the setup sequence, the decisions behind it and what goes wrong.

On this page

How promptfoo runs in a GitLab CI job

promptfoo runs as a command-line job in GitLab CI, using the node:24 image, following the official GitLab CI example in the promptfoo docs: Setting up Promptfoo with GitLab CI. The job installs Node.js dependencies, runs the promptfoo CLI against your eval configuration and lets the exit status decide whether the pipeline passes. There is no separate GitLab connector or plugin to install. The CLI is the integration point, which means any team that can write a .gitlab-ci.yml job with a script block can run it. promptfoo is released under the MIT license, so the tool itself carries no license fee and can be pinned to a specific npm version for repeatable runs.

The execution model matters for security planning. promptfoo's documentation states that it runs completely locally: evals execute on the machine that runs the job and talk directly with the model provider. In GitLab terms, that machine is the runner. Your provider API keys must therefore be present in the runner's environment during the job, and eval datasets, prompts and model responses are processed on the runner and sent to the provider you configured. Nothing is routed through a promptfoo-hosted service in this setup. Decide early which runners will execute these jobs, whether they are shared or project-specific, and who can read their job logs and artifacts, because those are the places where a misconfigured job would expose keys or data.

Before you copy the example, confirm three things with your own environment: the Node.js version your chosen promptfoo release requires, which the npm registry and GitHub releases list, whether your runners can reach your model provider endpoints from their network segment, and whether your organization's policy allows the runner image to be pulled from the registry you use. The example image is a starting point, not a requirement. Air-gapped or restricted networks will need a mirrored image and a provider endpoint the runner can reach, and that work is usually the largest unknown in the first rollout.

What you need before the first GitLab pipeline run

Most failed first runs trace back to a missing piece of the environment rather than the promptfoo configuration itself. The cards below cover the Node.js version, the runner, the project settings, provider credentials and network path, each of which should be confirmed before the job is written.

Node.js version on the job image

The promptfoo 0.124.1 release requires Node.js 22.22.0 or newer, and the documented GitLab example uses the node:24 image, which satisfies that floor. Pin the image tag in your job so a silent base image change does not alter the runtime. Confirm the version you run locally matches the one in CI, since differences in Node.js can surface as install or startup errors that look like promptfoo bugs.

promptfoo on npm

A runner with a Docker executor

Your GitLab Runner needs an executor that can start the Node.js image for each job. A Docker executor is the usual choice because it gives each run a clean environment and matches the documented example. Ask your platform team which runner tags are available to merge request pipelines, and confirm that shared runners are permitted to hold provider credentials for your project.

GitLab Runner docs

Merge request pipelines enabled

The job should run on merge request events so that a regression blocks the change before it merges. Confirm that merge request pipelines are enabled for the project and that the workflow rules do not suppress them. Check who can approve pipeline changes, because editing the .gitlab-ci.yml file is a common way for a change to bypass the eval gate.

Provider accounts and API keys

Each model provider the eval calls needs an account, a key with a spend limit, and an owner who can rotate it. Ask finance or the platform owner who pays for CI model calls and whether a separate key is issued for pipelines. Store the keys as masked, protected CI/CD variables in the project or group settings, not in the repository, and confirm the grader model's key is also available.

Network egress to the model provider

The runner must reach the provider API endpoint over the network, which may require an outbound proxy or an allow-list entry on your firewall. For self-managed GitLab, confirm that the runners sit in a network segment that can reach the provider, or that a model endpoint is hosted inside your network. In air-gapped setups, the eval needs a model endpoint inside that network, and GitLab's offline guidance should be read first.

GitLab offline environments

A model endpoint for air-gapped installs

Where the network has no route to a public provider, the eval must point at a model served inside the environment. Confirm which models are approved, how the endpoint is authenticated, and whether it accepts the request format your promptfoo provider configuration expects. Test one eval case from a runner before writing the full pipeline, because connectivity failures often appear only after the job starts.

Configure the promptfoo job in .gitlab-ci.yml

This sequence moves from secrets to a working pipeline job: provider keys stored as protected, masked variables, a Node.js job that caches promptfoo responses, and a rule that runs evals only in merge request pipelines. Each step ends with a check you can run before trusting the job.

  1. Store provider keys as masked and protected variables

    In the GitLab project settings, add each model provider key (for example, the API key for the model under test and the grader) under CI/CD variables. Mark each one as masked so GitLab hides its value in job logs, and as protected so it is only exposed to pipelines running on protected branches or tags if you choose that setting. Keep keys out of .gitlab-ci.yml and out of promptfooconfig.yaml. The step is done when the variables are listed in settings with their values hidden.

  2. Define the job on the node:24 image

    Create a job in .gitlab-ci.yml that uses the node:24 image, the image the promptfoo GitLab CI example uses. Give the job a clear name such as promptfoo-eval so reviewers can find it in the merge request pipeline. Confirm with your platform team that your runners can pull this image, including in any offline or mirrored registry you operate. The step is done when a pipeline shows the job starting on a runner with Node.js available.

  3. Point the cache path at promptfoo's cache directory

    Set the PROMPTFOO_CACHE_PATH variable to .promptfoo/cache in the job's variables block. This tells promptfoo where to keep stored model responses, which is what makes later runs cheaper. Keep the path inside the project directory so GitLab can cache it. The step is done when the job's variables show the path and the first run creates that directory.

  4. Add a cache entry keyed to the lockfile or config

    Add a cache block that stores the .promptfoo/cache path between pipelines. Set the cache key to a value derived from your package-lock.json and promptfooconfig.yaml, so a change to either creates a new cache and avoids serving stale results. Ask your team whether prompt files and test data should also be part of the key. The step is done when the first pipeline finishes and GitLab shows a cache archive for this key.

  5. Install promptfoo and run the eval

    In the script section, install promptfoo from npm and run promptfoo eval against your configuration file. Confirm the version you install against the current npm release and the Node.js requirement stated on the npm package page, and pin the version in your lockfile so pipelines behave the same way. Store the results file as a job artifact if reviewers need it. The step is done when the job log shows the eval summary with pass and fail counts.

  6. Restrict the job to merge request pipelines

    Add a rules block so the job runs only when a merge request pipeline starts, using the merge request pipeline rule in GitLab. This keeps eval spend tied to proposed changes instead of every branch push. Check the rule against your branch naming and any scheduled pipelines you run separately. The step is done when a push to a branch without an open merge request does not start the job, and opening a merge request does.

  7. Verify masking, cache hits and failure behavior

    Run three checks before relying on the job. First, confirm a provider key does not appear in the job log, even if a script prints environment variables. Second, run a second pipeline without changing prompts or config and confirm the log reports cached responses, which shows the cache is restored. Third, add a deliberately failing assertion on a test branch and confirm the job exits with a failure status that blocks the merge request. The step is done when all three checks pass and you have recorded the results.

Using the promptfoo cache to cut API spend between pipelines

The documented GitLab CI example stores promptfoo's cache at .promptfoo/cache and sets PROMPTFOO_CACHE_PATH to that directory, then saves it as a GitLab cache entry. Unchanged prompts and test cases can then reuse model responses from earlier pipelines instead of calling the provider again, which lowers the API spend of frequent merge request runs. The saving depends on the cache surviving between jobs, so the cache setup is the part of the job to review before you rely on the numbers. The official setup guide is in the promptfoo GitLab CI documentation.

The cache key controls when stored responses are reused, and it has to change when the inputs that shape a response change. That means prompt files, the promptfoo configuration, test case data and the model or grader settings. If the key only depends on the branch name or a static string, a prompt change can be graded against responses generated for the old prompt, and a real regression can pass unnoticed. Treat a cache hit as a reason to check the key, not as proof that the eval ran against the current code. Also plan for the cache growing over time: each stored response takes runner or object storage space, and old entries accumulate across branches.

Before you rely on the cache, confirm three things in your own environment: how your key is built from the files that affect results, whether your GitLab Runners keep the cache between jobs (shared runners, autoscaling and ephemeral runners behave differently), and how much storage the cache may use. Run one pipeline on an unchanged branch and a second one after a deliberate prompt edit, and check that the second run calls the provider again. Keep a periodic full run without the cache so a stale entry cannot hide drift for long. The GitLab Runner documentation explains the runner side of caching.

How a merge request run reaches the model provider

The run starts when a developer pushes to a merge request and GitLab schedules the pipeline on a runner. The job restores the promptfoo cache, then promptfoo reads the config and test cases on the runner and calls the model provider directly with keys taken from masked CI variables. Results and new cache entries are written back on the runner, and the exit code tells GitLab whether the merge request passes. Check that the provider call is the only step that crosses the trust boundary, and that keys never appear in job logs.

Data flow from a merge request push to the external model provider, with the trust boundary at the runner.

Mapping GitLab CI variables and artifacts to promptfoo settings

This table pairs each GitLab CI element with its role in a promptfoo run, from masked provider keys to the cache entry, merge request status and job artifacts. Read it as a checklist when you write the job, and confirm exact variable names against the provider configuration your team chooses.

GitLab elementpromptfoo roleWhat to check
Masked and protected CI/CD variablesHold provider API keys, which promptfoo reads from the environment at run timeMark keys as masked and protected, and confirm the variable names match what your provider configuration expects
PROMPTFOO_CACHE_PATH and cache entryPoint promptfoo's response cache at .promptfoo/cache so responses persist between pipelinesKey the GitLab cache entry to that same path, and confirm the cache is restored before the eval starts
Job exit codeA failing eval or threshold makes the job exit non-zeroConfirm the job is required to pass before merge, since merge request status follows the job result
Merge request pipelineRuns the eval against proposed prompt or code changes before they reach the target branchConfirm the job runs on merge request events, not only on the default branch
Job artifactsKeep result files such as JSON, HTML or JUnit output for review after the job finishesSet an expiry that fits your review cycle, and check that artifacts may contain prompts and model outputs
Runner environmentProvides the Node.js image the job runs on and the network path to model providersConfirm the runner can reach the provider endpoints, and that the image version meets promptfoo's Node.js requirement

Protecting provider keys and eval data in GitLab

A promptfoo job in GitLab CI needs provider keys at run time and produces outputs that can echo prompts, documents and model responses. The cards below cover where those values can leak, which GitLab settings narrow the exposure, and what to confirm in your own project and runner configuration before the first merge request runs.

Masked and protected variables

Masking hides a value in job logs, but it does not stop a script from printing it. A promptfoo config or a debug flag can echo an environment variable into the log or into a report, and masking only matches the exact string it was given. Mark provider keys as protected so they are exposed only to jobs on protected branches, and test that a deliberately broken step still hides the key. Confirm the current variable options in GitLab's CI/CD documentation for your version.

GitLab hardening guidance

Restricting keys to protected branches

Protected variables reach only pipelines on branches or tags that your project protects, so an unreviewed feature branch cannot read the production provider key. Decide which branches may run full evals with live keys, and whether merge request pipelines should use a smaller key with a spend limit. Check protected branch rules and who may push to them in your project settings.

Merge requests from forks

A merge request from a fork can change .gitlab-ci.yml, so the job definition itself becomes untrusted code. Review how your project handles pipelines for forked changes, which users may approve and merge, and whether external contributors can trigger jobs that receive secrets. Keep provider keys out of any pipeline that runs untrusted configuration, and confirm these settings against GitLab's authentication and authorization documentation.

GitLab authentication docs

Shared runner trust

A shared runner may serve many projects, so a job that writes to a cache or a local file can affect later jobs. Use runners dedicated to trusted projects for jobs that hold live keys, and review whether Docker executors on those runners are isolated from each other. Confirm the executor, tags and locking options in the GitLab Runner documentation before assigning the promptfoo job to a shared pool.

GitLab Runner docs

Secrets in test case files

Test case files, prompt files and promptfoo configs are committed to the repository and read by every contributor and every pipeline. A real customer record, an internal URL or a token pasted into a test case stays in git history even after deletion. Keep credentials in CI variables, use synthetic or redacted test data, and scan test files for secret patterns in a pre-commit or pipeline check.

What eval outputs contain

Eval results, HTML reports and JSON files record the prompts sent, the model responses and sometimes the retrieved documents or tool outputs. Once published as job artifacts, those files are readable by anyone with access to the pipeline, so they can expose personal or regulated data. Set short artifact expiry, limit who can download artifacts, and decide what the report must omit before you publish it.

Why the first GitLab promptfoo job fails and how to fix it

This table lists the failures teams most often hit when a promptfoo job first runs in GitLab CI, with the likely cause and the fix for each. Read it top to bottom when a job fails, or scan the cause column to check your configuration before the first pipeline runs.

FailureLikely causeFix
Node version mismatchThe job image runs an older Node.js than the installed promptfoo release requires, which is 22.22.0 or newer for release 0.124.1.Use the node:24 image in the job, or pin a Node.js 22.22.0 or newer image, and confirm the version with node --version in the first script line.
Provider authentication errorsProvider keys are missing from CI/CD variables, not masked, scoped to another branch, or named differently from the config file.Define each key as a masked and protected CI/CD variable, match the exact names referenced in the config, and check that the job runs on a branch or tag where protected variables are available.
Cache not restoredThe cache key changed, or PROMPTFOO_CACHE_PATH points somewhere other than the path listed in the cache entry, so nothing is saved or reloaded.Set PROMPTFOO_CACHE_PATH to .promptfoo/cache and use the same path in the cache block. Use a stable key, and check the job log for a cache restore message on the second pipeline.
Merge request pipeline not triggeredThe rules block only runs on branch pushes, or the workflow rules exclude merge request events, so GitLab never creates the job.Add a rule for merge request events, such as the predefined merge request pipeline source, and confirm the pipeline appears on the merge request page after a push.
Runner blocks the providerThe runner sits behind a proxy or firewall, or its network cannot reach the model provider's endpoint, so requests time out or fail to connect.Test outbound HTTPS from the runner to the provider endpoint, configure proxy variables if your network needs them, and ask your platform team which egress rules apply to the runner.
Flaky model-graded assertions fail mergesAn LLM-as-a-judge check gives different grades on identical outputs, so the pass rate moves between runs without a real regression.Pin the grader model and temperature, review the failing rows, and set a pass-rate threshold or retry policy only after you have confirmed the failures are noise rather than a regression.
Job exits successfully with no resultsThe eval command runs without a valid config path or the working directory is wrong, so no test cases execute.Check the config path relative to the job's working directory and confirm the log lists the expected number of test cases before relying on the exit code.

Questions teams ask before running promptfoo in GitLab CI

Does running promptfoo in GitLab CI cost anything beyond provider usage?

The promptfoo software itself costs nothing to run in a pipeline, because promptfoo is MIT licensed and the Community edition is free, including its LLM evaluation features and 10k red teaming probes per month. The recurring costs are the model calls your evals make, the GitLab runner compute that executes the job, and any grader model calls used for model-graded checks. Paid promptfoo Enterprise pricing is custom and only applies if you want team sharing, SSO or centralized monitoring, which the CI job does not require. Ask your provider for their current token pricing and confirm runner minutes or hosting costs in your own GitLab environment.

How long does a promptfoo GitLab CI job take to set up?

The basic job is a short configuration change: a pipeline stage using a Node.js image, an install step, a cache entry and an eval command. The effort grows with the number of things your team has to decide and verify, including which provider accounts the job uses, how many test cases exist and whether they are already in version control, how the cache key is designed, and whether merge requests must fail on a pass-rate threshold. Runner availability, network access to model endpoints and your change control process can add time. No duration is given here, so ask for a written scope with a timeline that lists these items.

What does our team need to supply for the promptfoo job?

Your team needs to supply three things before the job can run. First, provider accounts and API keys for each model the evals call, with spending limits you are comfortable with. Second, GitLab runner access: a runner that can reach the model endpoints, with Node.js available or pulled through the image, and permission to set masked variables in the project or group. Third, test cases and eval configuration, such as a promptfoo config file, prompts and expected outputs that reflect your application. Confirm runner network rules, egress policies and secret management standards in your own environment, since these vary by organization.

Can our in-house team set up promptfoo in GitLab CI alone?

Yes, a team with GitLab CI experience and someone who owns the LLM application can usually build the first job without outside help, because the promptfoo GitLab CI example is a documented starting point. The harder parts are usually outside the YAML: writing assertions that catch real regressions, deciding what a fair pass-rate threshold is, keeping provider keys out of logs and reviewing whether the cache stores data you are comfortable keeping. Partner help is most useful when scope is large, several pipelines must be covered or security review of the setup is required. DeployOpen can plan and implement this work under a written scope if you prefer that route.

Does our GitLab tier change how the promptfoo job works?

No. A promptfoo eval job is an ordinary GitLab CI job, so it runs on GitLab Free, Premium or Ultimate as long as your installation supports the CI features it uses. Tier differences concern other capabilities: the GitLab pricing page lists advanced CI/CD and priority support for Premium, and application security testing, software supply chain security, vulnerability management and compliance features for Ultimate. Those features are separate from running promptfoo. Check your current tier in your own instance before you plan any work that depends on a specific feature.

How do we reduce LLM API spend from promptfoo CI runs?

The main lever is the promptfoo cache. The GitLab example sets PROMPTFOO_CACHE_PATH to .promptfoo/cache and saves that path as a GitLab cache entry, so unchanged test cases can reuse earlier responses between pipelines. Other levers include running the full suite only when prompts or configs change, choosing cheaper grader models for model-graded assertions, limiting concurrency and avoiding scheduled runs that repeat the same tests. Confirm with your provider how cached responses interact with their terms and rate limits, and review the cache key so that a changed prompt invalidates stale entries.

How do we keep provider keys safe in the promptfoo job?

Store each provider key as a masked, protected variable in GitLab rather than in the YAML file or the repository. Masking hides values in job logs, and protected variables are only exposed to protected branches, which limits who can read them from a merge request. Keep the job's scope narrow, use separate keys for CI and for local development, and rotate keys on a schedule your security team sets. Also check that eval output, which can include prompts and responses, is not stored as a public artifact. Confirm the masking and protection rules that apply to your GitLab instance and branch model.

Keeping the pipeline working through promptfoo and GitLab upgrades

Two moving parts can break this job without anyone touching the YAML: the promptfoo version installed by the job and the Node.js image it runs on. promptfoo's current npm release, 0.124.1, requires Node.js 22.22.0 or newer, and the example job uses the node:24 image. When promptfoo raises its runtime requirement, or when a new promptfoo release changes behavior your assertions depend on, the job can fail on install or produce different results. Pin the promptfoo version in package.json or in the install command, record the image tag you rely on, and change either one only in a deliberate commit. Confirm the current Node.js requirement in the promptfoo releases notes before each bump, since the requirement is stated per release.

GitLab changes on its own schedule, and that affects the pipeline as much as the application does. GitLab ships a minor release on the third Thursday of each month and a major release each year, and self-managed instances must pass through required upgrade stops, which fall at versions x.2, x.5, x.8 and x.11. After each GitLab upgrade, recheck the .gitlab-ci.yml keywords the job uses, the cache and variable behavior, and the version of GitLab Runner that executes the job, because runner and server versions are expected to be kept reasonably close. Read the GitLab upgrade paths page before scheduling the upgrade, and confirm the runner compatibility guidance in the GitLab Runner documentation for your version.

Test every change on a non-production project first. Use a sandbox project with the same runner tags, a low-spend provider key and a small eval suite, then run a pipeline that exercises the cache restore, the masked variables and a deliberately failing assertion to confirm the merge request still blocks. Keep the test pipeline in the same repository so the reviewer can see the diff that changed the version. Ask your platform team to confirm which GitLab instance version and runner version each project uses, so an upgrade plan covers every pipeline that depends on promptfoo.

How DeployOpen scopes and delivers promptfoo in GitLab CI

DeployOpen plans and builds the promptfoo eval job inside the GitLab instance and runners you control, then documents and hands it over to your team. Engagements start with a written scope that names the suites, the provider keys, the cache design and the merge request rules before any pipeline changes are made.

How we scope

  • The written scope names which eval and red team configs run in merge requests and which run on a schedule.
  • We record the GitLab edition, runner type and Node.js image your organization has approved.
  • Provider keys, masked variable ownership and the list of model providers are agreed before the first job runs.
  • The scope states the pass-rate threshold, the regression rule and who approves changes to it.
  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.

How we build

  • We write the .gitlab-ci.yml job, set PROMPTFOO_CACHE_PATH and configure the GitLab cache entry for it.
  • Masked and protected variables are configured so provider keys stay out of job logs and forked pipelines.
  • We test failing and passing merge requests to confirm the job blocks regressions as the written scope requires.
  • Cache behavior is checked across consecutive pipelines so spend savings are measured against your own runs.
  • Test runs cover the job, its artifacts and its access settings before anything is pointed at production branches.

How we hand over

  • You receive the pipeline configuration, variable inventory and cache design written for your team to maintain.
  • The runbook explains how to rotate provider keys, update the Node.js image and change the pass-rate threshold.
  • We walk your platform and security engineers through the job, its logs and how to read a failed gate.
  • Evidence of testing and access settings is delivered as documentation your compliance reviewers can read.
  • Ownership of the repository changes and the runner configuration is confirmed in the handover record.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the handover.
  • Retainers can cover promptfoo version changes, Node.js image updates and GitLab upgrade stops affecting the job.
  • Ask for the support scope, response expectations and upgrade testing approach in writing before signing.
  • Changes to the job are tested in a non-production project before they reach shared pipelines.
  • We can retest after pipeline or GitLab changes to confirm the gates and cache still behave as documented.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.