site/docs/integrations/gitlab-ci.md
This guide shows how to integrate Promptfoo's LLM evaluation into your GitLab CI pipeline. This allows you to automatically test your prompts and models whenever changes are made to your repository.
Create a .gitlab-ci.yml file in your repository root. Here's a basic configuration that installs Promptfoo and runs evaluations:
image: node:20
evaluate_prompts:
script:
- npm install -g promptfoo
- promptfoo eval -c promptfooconfig.yaml --prompts prompts/**/*.json --share -o output.json
variables:
OPENAI_API_KEY: ${OPENAI_API_KEY}
PROMPTFOO_CACHE_PATH: .promptfoo/cache
cache:
key:
files:
- prompts/**/*
paths:
- .promptfoo/cache
artifacts:
paths:
- output.json
reports:
json: output.json
rules:
- changes:
- prompts/**/*
OPENAI_API_KEY (or other provider keys) as masked and protected variablesThe configuration above includes caching to save time and API costs. The cache:
.promptfoo/cacheThe configuration stores the evaluation results as artifacts:
output.json--share flag creates a shareable web URL for resultsYou can add custom steps to process the evaluation results:
evaluate_prompts:
script:
- npm install -g promptfoo
- promptfoo eval -c promptfooconfig.yaml --prompts prompts/**/*.json --share -o output.json
- |
if jq -e '.results.stats.failures > 0' output.json; then
echo "Evaluation had failures"
exit 1
fi
For large test suites, you can use GitLab's parallel feature:
evaluate_prompts:
parallel: 3
script:
- |
prompts=$(find prompts -name "*.json" | awk "NR % $CI_NODE_TOTAL == $CI_NODE_INDEX")
promptfoo eval -c promptfooconfig.yaml --prompts $prompts
You can configure the job to post results as merge request comments:
evaluate_prompts:
script:
- npm install -g promptfoo
- |
OUTPUT=$(promptfoo eval -c promptfooconfig.yaml --prompts prompts/**/*.json --share)
SHARE_URL=$(echo "$OUTPUT" | grep "View results:" | cut -d' ' -f3)
echo "Evaluation Results: $SHARE_URL" | tee merge_request_comment.txt
artifacts:
reports:
junit: output.json
paths:
- merge_request_comment.txt
after_script:
- |
if [ -n "$CI_MERGE_REQUEST_IID" ]; then
curl --request POST \
--header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" \
--data-urlencode "body=$(cat merge_request_comment.txt)" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/notes"
fi
After the evaluation runs, you'll see:
Common issues and solutions:
Cache not working:
API key errors:
Job timing out:
evaluate_prompts:
timeout: 2 hours
For more details on Promptfoo configuration, see the configuration reference.