GitLab CI Integration
Add DriftWise to your .gitlab-ci.yml pipeline.
Pipeline Example
The analyze endpoint enqueues the job and returns 202 immediately —
poll GET /llm-jobs/{job_id} until status is done (or error):
plan:
stage: plan
script:
- terraform plan -out=tfplan
- terraform show -json tfplan > plan.json
- |
JOB_ID=$(curl -sfX POST "https://api.driftwise.ai/api/v2/orgs/$DRIFTWISE_ORG_ID/analyze" \
-H "x-api-key: $DRIFTWISE_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"plan_json\": $(cat plan.json | jq -Rs .),
\"ci\": {
\"repo_owner\": \"$CI_PROJECT_NAMESPACE\",
\"repo_name\": \"$CI_PROJECT_NAME\",
\"pr_number\": $CI_MERGE_REQUEST_IID,
\"commit_sha\": \"$CI_COMMIT_SHA\",
\"branch\": \"$CI_COMMIT_BRANCH\"
}
}" | jq -r '.job_id')
- |
for i in $(seq 1 36); do
BODY=$(curl -sf "https://api.driftwise.ai/api/v2/orgs/$DRIFTWISE_ORG_ID/llm-jobs/$JOB_ID" \
-H "x-api-key: $DRIFTWISE_API_KEY")
STATUS=$(echo "$BODY" | jq -r '.status')
if [ "$STATUS" = "done" ]; then RESULT=$(echo "$BODY" | jq '.result'); break; fi
if [ "$STATUS" = "error" ]; then echo "analysis failed: $(echo "$BODY" | jq -r '.error')" >&2; exit 1; fi
sleep 5
done
[ "$STATUS" = "done" ] || { echo "timed out waiting for analysis" >&2; exit 1; }
echo "risk_level=$(echo "$RESULT" | jq -r '.risk_level')"
CI/CD Variables
Add these in your project settings (Settings > CI/CD > Variables):
| Variable | Type | Masked | Value |
|---|---|---|---|
DRIFTWISE_API_KEY | Variable | Yes | Your API key (dw2_...) |
DRIFTWISE_ORG_ID | Variable | No | Your organization ID |
Notes
jqmust be available in your CI runner image (most Terraform images include it)- The
cimetadata block is optional but helps DriftWise link the analysis to the merge request analyzeenqueues the job and returns202immediately; pollGET /llm-jobs/{job_id}every 5s — analysis typically completes in 15–90s, and jobs are retained 7 days
Native Webhook (recommended)
In addition to the CI flow above, DriftWise can post analysis
results back as MR comments and respond to /driftwise commands.
1. Configure in DriftWise
Open Settings → Integrations → GitLab and click Connect GitLab.
Supply your project path (e.g. team/infra). DriftWise generates a
webhook secret — copy it immediately; it's shown only once.
2. Configure in GitLab
In your GitLab project, open Settings → Webhooks. Add a new webhook:
- URL:
https://api.driftwise.ai/webhooks/gitlab/<your-org-id> - Secret token: paste the secret from step 1
- Events: enable Merge request events and Comments
- Save
3. API token (optional)
To enable auto-comments on merge requests, paste a Project or Group
Access Token with the api scope during step 3 of the DriftWise wizard.
DriftWise validates the token against GitLab and stores its expiration —
you'll see a warning in the UI 30 days before it expires.
Skip this step to disable auto-comments. Without a token, DriftWise still receives MR events and logs them for correlation and diagnostics, but can't write back.
Self-hosted GitLab
Self-hosted instances are supported as long as they're reachable from the public internet. Air-gapped / VPN-only instances are not supported in Phase 1 — DriftWise SaaS must be able to resolve and route to your GitLab over public DNS and HTTPS.
Commands
Once configured, comment on any merge request:
/driftwise narrative— reposts the most recent analysis narrative
More commands will be added over time.