Type at least two letters.

    ↑ ↓ to moveEnter to open

    CI pipelines

    Audit a site after each deploy and fail the build when a high-severity check fails.

    Updated

    A deploy can quietly drop a security header, break the redirect to HTTPS or add a tracker. Auditing right after the deploy catches that before visitors do.

    What you need

    • A key with audits:read and audits:write, stored as a CI secret (METRICEVO_API_KEY).
    • The site’s id (SITE_ID), from GET /sites (or Automation → Try the API in the app).
    • curl and jq on the runner. Both are on the standard GitHub, GitLab and Bitbucket images.

    The script

    Save it as scripts/metricevo-audit.sh. It starts an audit, waits for it, prints every failed check, and exits with 1 if any of them is high severity.

    #!/usr/bin/env bash
    set -euo pipefail
    : "${METRICEVO_API_KEY:?}" "${SITE_ID:?}"
    API="${METRICEVO_API:-https://app.metricevo.com/api/v1}"
    auth=(-H "Authorization: Bearer $METRICEVO_API_KEY")
    
    # One key per pipeline run: a retry of this step returns the same audit.
    idem="ci-${CI_PIPELINE_ID:-${GITHUB_RUN_ID:-$(date +%s)}}-${SITE_ID}"
    
    response=$(curl -sS -X POST "$API/audit-runs" "${auth[@]}" \
      -H "Content-Type: application/json" -H "Idempotency-Key: $idem" \
      -d "{\"siteId\":\"$SITE_ID\"}")
    run=$(echo "$response" | jq -r '.id // .runId')   # 409 run_in_progress has runId
    [ "$run" = "null" ] && { echo "$response"; exit 2; }
    echo "Audit $run"
    
    for _ in $(seq 1 60); do
      status=$(curl -fsS "$API/audit-runs/$run" "${auth[@]}" | jq -r .status)
      case "$status" in queued|running) sleep 5 ;; *) break ;; esac
    done
    echo "Status: $status"
    [ "$status" = "failed" ] && exit 2
    
    fails=$(curl -fsS "$API/audit-runs/$run/observations?status=fail" "${auth[@]}")
    echo "$fails" | jq -r '.data[] | "\(.severity)\t\(.area)\t\(.summary)"'
    high=$(echo "$fails" | jq '[.data[] | select(.severity == "high")] | length')
    echo "High-severity findings: $high"
    [ "$high" -eq 0 ]
    

    Exit codes: 0 passed, 1 high-severity findings, 2 the audit could not run. Decide in your pipeline whether 2 should block a release.

    GitHub Actions

      audit:
        needs: deploy
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - name: Metricevo audit
            env:
              METRICEVO_API_KEY: ${{ secrets.METRICEVO_API_KEY }}
              SITE_ID: site_01JC9Z0000000000000000000
            run: bash scripts/metricevo-audit.sh
    

    GitLab CI

    metricevo-audit:
      stage: verify
      needs: [deploy]
      image: alpine:3
      before_script: [apk add --no-cache bash curl jq]
      script: bash scripts/metricevo-audit.sh
      variables:
        SITE_ID: site_01JC9Z0000000000000000000
    

    Set METRICEVO_API_KEY as a masked CI/CD variable.

    Good to know

    • The audit reads the live site. Run the step after the deploy is reachable, not before.
    • Limits. 20 audits per hour per account and one at a time per site. A busy pipeline on one site will meet run_in_progress; the script then follows the running audit.
    • Gate on what matters. Start by failing only on high; tighten later. no_data and not_tested never fail the build.