Merge Gate from Any CI
Just want to do it in the dashboard? See the guide: Create a service account for CI.
A CI job can drive OpenTremor without a code host integration. Send the change’s diff to
POST /v1/{changeset}/analyze/auto, wait for the
run, then read GET /v1/changesets/{changeset}/gate.
Exit with a non-zero status unless the gate says success. Configure the code host to require
successful pipelines or builds before merging.
Use this approach when the code host has no native integration, when OpenTremor has no public URL that a webhook can reach, or when you want the gate inside an existing pipeline. The CI job calls OpenTremor, so the server does not need to reach the code host.
Compared with the GitHub App, this approach does not post a report comment on the merge request. The job log prints the gate state and description. Triage in the dashboard changes the gate answer. Re-run the job to read the updated gate.
What you need
Section titled “What you need”- An API key for the organization with
analysis:runandanalysis:read, stored as a masked CI variableOPENTREMOR_API_KEY. - A stored LLM connection and a model allowed for it. The CI job does not need an LLM key when the connection stores one.
OPENTREMOR_URL, the API’s base URL as the CI runner reaches it.- The packs this change needs, enabled for the organization. The job sends no repository, so it uses the organization’s packs. If no pack matches, the analysis returns
422and the job fails.
The script
Section titled “The script”The same script runs on any CI. It needs git, curl and jq.
#!/bin/sh# usage: opentremor-gate.sh <changeset> <base-ref>set -euchangeset="$1"; base="$2"api() { curl -fsS -H "X-API-Key: $OPENTREMOR_API_KEY" -H "Content-Type: application/json" "$@"; }
git diff "$base...HEAD" > /tmp/change.diffresponse=$(jq -n --rawfile raw_input /tmp/change.diff \ --arg connection_id "$OPENTREMOR_CONNECTION" --arg model "$OPENTREMOR_MODEL" \ '{connection_id: $connection_id, model: $model, raw_input: $raw_input}' | api -X POST "$OPENTREMOR_URL/v1/$changeset/analyze/auto" -d @-)
# Small inputs run inline; larger inputs run as background jobs.job_id=$(echo "$response" | jq -r '.job_id')while :; do job_status=$(api "$OPENTREMOR_URL/v1/jobs/$job_id" | jq -r '.status') case "$job_status" in done) break ;; failed|cancelled) echo "OpenTremor analysis $job_status (job $job_id)"; exit 1 ;; esac sleep 10done
gate=$(api "$OPENTREMOR_URL/v1/changesets/$changeset/gate")echo "OpenTremor: $(echo "$gate" | jq -r '.state') — $(echo "$gate" | jq -r '.description')"[ "$(echo "$gate" | jq -r '.state')" = "success" ]Name the changeset after the merge request. Each push then adds a revision to the same changeset, and the dashboard shows one history per merge request.
GitLab CI
Section titled “GitLab CI”opentremor: image: alpine:3 rules: - if: $CI_PIPELINE_SOURCE == "merge_request_event" variables: GIT_DEPTH: 0 OPENTREMOR_CONNECTION: anthropic OPENTREMOR_MODEL: claude-sonnet-5 before_script: - apk add --no-cache git curl jq script: - git fetch origin "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME" - sh opentremor-gate.sh "gl-$CI_PROJECT_ID-$CI_MERGE_REQUEST_IID" "origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"Then enable Settings → Merge requests → Pipelines must succeed. This setting is available on every GitLab tier, including Free.
Bitbucket Pipelines
Section titled “Bitbucket Pipelines”pipelines: pull-requests: '**': - step: name: OpenTremor image: alpine:3 clone: depth: full script: - apk add --no-cache git curl jq - export OPENTREMOR_CONNECTION=anthropic OPENTREMOR_MODEL=claude-sonnet-5 - git fetch origin "$BITBUCKET_PR_DESTINATION_BRANCH" - sh opentremor-gate.sh "bb-$BITBUCKET_REPO_SLUG-$BITBUCKET_PR_ID" "origin/$BITBUCKET_PR_DESTINATION_BRANCH"Reading the answer
Section titled “Reading the answer”state | Exit code | Meaning |
|---|---|---|
success | 0 | No finding or unanalysed unit holds the change |
failure | 1 | An open CRITICAL or HIGH finding |
pending | 1 | A unit has no analysis, a finding needs human review, or an untriaged agent-injection finding holds the gate |
pending fails the job on purpose: a gate nobody has reviewed yet is not a pass. Triage the
findings in the dashboard, then re-run the job.