CI/CD integration
Run CodeStax from your pipeline so a pull request or release is blocked when it fails your policy. There are two gates:
| Gate | What it checks | Start here |
|---|---|---|
| PR review gate | A CodeStax review of the pull or merge request, against your quality-gate policy | Generate a template in the dashboard |
| SCA gate | The latest dependency scan of the repository, against a severity threshold | Gate a pipeline on dependency risk |
Prerequisites
- A repository connected to CodeStax. Note its numeric repository ID.
- An API key, created under Settings → API keys, stored as a masked secret in your CI system. The examples here name it
CODESTAX_API_KEY.
CI needs an API key, and the Free plan includes 0 API keys. API keys are available on Growth (up to 5 keys), Pro (up to 20) and Enterprise (unlimited). Send the key in the X-API-Key header; a key sent as Authorization: Bearer is rejected.
Give the key only the scopes its pipeline needs:
| Pipeline | Required scopes |
|---|---|
| PR review gate (template) | write:reviews |
| SCA gate, check only | read:sca |
| SCA gate that also triggers a scan | write:sca and read:scans |
| SCA badge or snippets | read:sca |
Generate a template in the dashboard
- Open PR reviews → CI/CD integration (
/dashboard/reviews/cicd). - Choose GitHub Actions, GitLab CI or Bitbucket Pipelines.
- Follow Setup instructions:
- Add CODESTAX_API_KEY secret. Click Copy name for the secret name, or Generate API key to open Settings → API keys.
- Copy the template below. Use the copy button on the template.
- Commit to your repository at the path for your provider:
| Provider | Path |
|---|---|
| GitHub Actions | .github/workflows/codestax-review.yml |
| GitLab CI | Add the job to .gitlab-ci.yml |
| Bitbucket Pipelines | Add the step to bitbucket-pipelines.yml under pipelines.pull-requests |
Every template does the same three things:
- Triggers a review of the current pull request with
POST /api/reviews/trigger-by-repo, using the provider’s own repository path and pull-request number (github.repositoryand the PR number on GitHub,CI_PROJECT_PATHandCI_MERGE_REQUEST_IIDon GitLab,BITBUCKET_REPO_FULL_NAMEandBITBUCKET_PR_IDon Bitbucket). - Polls
GET /api/reviews/{review_id}every 10 seconds, up to 60 times, until the review iscompletedorfailed. - Reads
GET /api/reviews/{review_id}/gateand fails the job unless the gate ispassed.
The GitHub template runs on pull_request opened and synchronize. The GitLab job runs on merge-request pipelines. The Bitbucket step runs for every pull request and installs curl and jq in an alpine:3.20 image.
To fetch a template from a script, call the same endpoint the page uses:
$ curl -H "X-API-Key: $CODESTAX_API_KEY" \
"https://codestax.co/api/reviews/cicd/template?provider=bitbucket"provider is github (default), gitlab or bitbucket. The response is {"provider": "...", "template": "..."}.
The review gate uses the policy captured by the review itself. Thresholds cannot be overridden from the pipeline. Configure them under Settings → Policies; see Set up quality gates.
Gate a pipeline on dependency risk
The SCA gate evaluates the repository’s latest dependency scan and passes only when that scan is complete, its coverage is clean, and no active finding meets your threshold.
$ curl -X POST "https://codestax.co/api/sca/cicd/check" \
-H "X-API-Key: $CODESTAX_API_KEY" \
-H "Content-Type: application/json" \
-d '{"repo_id": <repo_id>, "branch": "main", "fail_on": "high"}'| Field | Required | Values |
|---|---|---|
repo_id | Yes | Numeric repository ID |
branch | No | Evaluate the latest scan of this branch; omit for the latest scan of any branch |
fail_on | No | critical (default), high, medium, low or any |
The response always has a boolean passed, a status and a human-readable reason:
status | passed | Meaning |
|---|---|---|
passed | true | The latest scan is complete and clean with no active finding at or above fail_on |
blocked | false | blocking_count active findings meet the threshold; the first 20 are listed in blocking_issues |
no_scan | false | No dependency scan exists for the repository or branch |
incomplete_scan | false | The latest scan is still running, failed, or completed without clean coverage |
incomplete_inventory | false | The scan has dependency findings but no stored component inventory, so the gate cannot be verified |
A passing or blocked result also includes summary with critical, high, medium, low, kev and total_active counts. Findings triaged as accepted risk, not applicable, false positive, won’t fix or fixed do not count.
A missing scan always fails the gate. This is the organization’s CI/CD evidence policy, shown under Dependencies → Settings → Notifications & SLA; pipeline requests cannot weaken it.
Add an SCA gate step to GitHub Actions
CodeStax does not publish a marketplace action. Copy this composite action into your repository and reference it by path.
# .github/actions/codestax-sca/action.yml
name: 'CodeStax SCA Security Check'
description: 'Trigger and enforce a CodeStax dependency-security policy gate'
inputs:
api-url:
description: 'CodeStax API URL, including /api'
required: true
api-key:
description: 'CodeStax API key (read:sca; add write:sca and read:scans to trigger scans)'
required: true
repo-id:
description: 'Numeric repository ID in CodeStax'
required: true
fail-on:
description: 'Minimum severity that fails the check: critical, high, medium, low or any'
required: false
default: 'critical'
trigger-scan:
description: 'Trigger a new SCA scan and wait for it before checking'
required: false
default: 'false'
outputs:
passed:
description: 'Whether the policy check passed'
value: ${{ steps.check.outputs.passed }}
scan-id:
description: 'The scan evaluated by the gate'
value: ${{ steps.check.outputs.scan-id }}
blocking-count:
description: 'Findings that meet the threshold'
value: ${{ steps.check.outputs.blocking-count }}
runs:
using: 'composite'
steps:
- id: check
shell: bash
env:
API_URL: ${{ inputs.api-url }}
API_KEY: ${{ inputs.api-key }}
REPO_ID: ${{ inputs.repo-id }}
FAIL_ON: ${{ inputs.fail-on }}
TRIGGER_SCAN: ${{ inputs.trigger-scan }}
run: |
set -euo pipefail
api="${API_URL%/}"
auth=(-H "X-API-Key: ${API_KEY}" -H "Accept: application/json")
scan_id=""
if [ "$TRIGGER_SCAN" = "true" ]; then
scan_id=$(curl --fail --silent --show-error "${auth[@]}" \
-H "Content-Type: application/json" -X POST "$api/sca/scan" \
-d "$(jq -cn --argjson id "$REPO_ID" '{repository_id: $id}')" | jq -er '.scan_id')
for attempt in $(seq 1 60); do
scan=$(curl --fail --silent --show-error "${auth[@]}" "$api/scans/$scan_id")
status=$(echo "$scan" | jq -r '.status')
case "$status" in
completed)
[ "$(echo "$scan" | jq -r '.scan_health')" = "clean" ] \
|| { echo "::error::Scan $scan_id completed without clean coverage"; exit 1; }
break ;;
failed|cancelled)
echo "::error::Scan $scan_id ended as $status"; exit 1 ;;
esac
[ "$attempt" -lt 60 ] || { echo "::error::Timed out waiting for scan $scan_id"; exit 1; }
sleep 10
done
fi
result=$(curl --fail --silent --show-error "${auth[@]}" \
-H "Content-Type: application/json" -X POST "$api/sca/cicd/check" \
-d "$(jq -cn --argjson id "$REPO_ID" --arg f "$FAIL_ON" '{repo_id: $id, fail_on: $f}')")
gate_scan=$(echo "$result" | jq -r '.scan_id // empty')
if [ -n "$scan_id" ] && [ "$gate_scan" != "$scan_id" ]; then
echo "::error::Gate evaluated scan ${gate_scan:-none} instead of $scan_id"; exit 1
fi
passed=$(echo "$result" | jq -r '.passed')
{
echo "passed=$passed"
echo "scan-id=$gate_scan"
echo "blocking-count=$(echo "$result" | jq -r '.blocking_count // 0')"
} >> "$GITHUB_OUTPUT"
if [ "$passed" != "true" ]; then
echo "::error::$(echo "$result" | jq -r '.reason')"; exit 1
fi
echo "CodeStax SCA gate passed."Use it from a workflow:
# .github/workflows/codestax-sca.yml
name: CodeStax SCA gate
on:
pull_request:
branches: [main]
jobs:
sca-gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/codestax-sca
with:
api-url: https://codestax.co/api
api-key: ${{ secrets.CODESTAX_API_KEY }}
repo-id: ${{ vars.CODESTAX_REPO_ID }}
fail-on: high
trigger-scan: 'true'With trigger-scan: 'true' the step starts a dependency scan, waits up to 10 minutes for it to finish with clean coverage, then gates on that exact scan. With the default 'false', it gates on the latest existing scan.
Get snippets for other CI systems
GET /api/sca/cicd/snippets returns ready-to-paste SCA gate snippets for GitHub Actions, GitLab CI, Jenkins and a Shell Script, plus a contract object describing the result field (passed) and the authentication header (X-API-Key).
$ curl -H "X-API-Key: $CODESTAX_API_KEY" \
"https://codestax.co/api/sca/cicd/snippets" | jq -r '.snippets[] | select(.name == "Jenkins") | .code'Each snippet calls POST /api/sca/cicd/check with fail_on: critical and fails the job unless passed is true. Edit fail_on to match your threshold. The snippets are available only from the API today.
SCA status badge
GET /api/sca/cicd/badge/{repository_id} returns an SVG badge for the latest dependency scan. Add ?branch=<branch> to select a branch.
| Badge text | When |
|---|---|
passing | The latest scan is complete and clean with no vulnerability findings |
N critical | The latest clean scan has critical findings |
N vulns | The latest clean scan has findings, none critical |
no scan | No dependency scan exists |
scan running, scan failed, incomplete and similar | The latest scan is not complete or its coverage is not clean |
The badge endpoint requires an API key, like every SCA endpoint. A public README image cannot send that header, so use the badge from an authenticated dashboard, script or internal page rather than embedding it directly in a public README.
The same release-gate check and badge drive the Release gate panel on Dependencies → Overview, which evaluates at the high threshold.
Use the CodeStax CLI
The CodeStax CLI wraps the PR review gate in one command. It is not published as a package; see CLI installation. review triggers the review, waits for it, and enforces the gate:
$ codestax review <repo_id> <pr_number>To run the steps separately:
# Trigger a review and wait for it to finish (prints the review ID)
$ codestax trigger <repo_id> <pr_number> --wait
# Enforce the quality gate against a completed review
$ codestax gate <review_id>The CLI reads the same immutable, versioned gate snapshot that the review published to GitHub, GitLab or Bitbucket, so its result cannot diverge from the provider signal. The gate is passed, failed or inconclusive. Incomplete, degraded, unverified, missing or inconsistent evidence is inconclusive and must not be treated as a pass or an ordinary policy failure. See the CLI exit codes.
Troubleshooting
| Issue | Solution |
|---|---|
401 or 403 from the API | Check that the key is sent as X-API-Key, has not expired, and has the scopes in the table above |
Repository not found or Access denied | Check that the repository is connected to the same organization as the key, and that the repository ID is its numeric ID |
SCA gate returns no_scan | Run a dependency scan for the repository or branch, or set trigger-scan: 'true' |
SCA gate returns incomplete_scan | Wait for the running scan to finish, or inspect the scan’s coverage warnings |
| Template job times out | The review did not finish within 60 polls; re-run the job |
CLI Gate pending (exit code 2) | The review had not finished; the review command waits automatically, so re-run the step |
CLI Gate inconclusive (exit code 3) | Inspect analyzer coverage and the gate reasons; do not treat this as a pass |
CLI Review failed (exit code 4) | Inspect the review error; no trusted gate decision was available |
CLI Review timeout (exit code 5) | The review did not complete before the deadline |
CLI Authentication or API error (exit code 6) | Verify CODESTAX_API_KEY, the API URL, network access and the API response |