Guide
Gate builds on new findings
New to this? See Code and app security: what you get.
Failing a build on every finding a scanner reports blocks every team that has old findings. Logthread fails it only on new findings: the findings that the last full scan of the same service, branch and tool did not report. Old findings stay visible in Code security → Findings for triage and alerts; they do not stop the release.
How it decides#
Every upload to POST /api/scans answers with new_findings (by severity) and gate:
"new_findings": {"critical": 1, "high": 0, "medium": 2, "low": 0, "info": 0, "total": 3},
"gate": {"fail_on": "critical", "failed": true, "count": 1, "reason": "1 new finding at critical or above."}- The baseline is the last full scan of the same service, branch, kind and tool. A branch that has none yet (a new pull request branch) is compared with
base_branch, by defaultmainthenmaster. A pull request therefore fails only on what it adds. - The first scan of a service, branch and tool has nothing to compare with. Every finding in it is new, and the gate passes: that scan becomes the baseline. This includes a pull request whose base branch was never scanned: it is not gated until the base branch has a full scan, so run the pipeline on the default branch first.
fail_oniscritical(default),high,medium,lowornone(report only). The gate counts new findings at that severity or above.- Accepted risks and false positives never count. Mark a finding on
main, and the same finding on a new branch keeps that status. - Partial scans (
partial=true, a diff scan of changed files) are gated against the baseline too. They never resolve anything and never become the baseline.
The numbers are the stored ones: the scan's new findings are exactly the findings in Code security → Findings with *Findings of scan*, *Only new*. The answer for a typical report comes back in well under 2 seconds.
Make curl fail the build#
Add gate=fail. When the gate fails, the answer is HTTP 409 with the same body plus error.code: gate_failed, so curl --fail-with-body exits non-zero without any JSON tool. The scan is stored either way.
FAILED=0
curl -sS --fail-with-body -X POST "$LOGTHREAD_URL/api/scans" \
--url-query "service=checkout-api" --url-query "kind=secrets" --url-query "tool=gitleaks" \
--url-query "branch=$BRANCH" --url-query "commit=$COMMIT" \
--url-query "fail_on=high" --url-query "gate=fail" \
-H "Authorization: Bearer $LOGTHREAD_API_KEY" -H "Content-Type: application/octet-stream" \
--data-binary @gitleaks.sarif || FAILED=1
# ... one upload per report ...
exit $FAILEDUpload every report first and fail at the end, so one failing tool does not hide the others' results. The pipeline files from Code security → Code scans in CI do exactly this (see Scan your code in CI).
Per CI system#
The guided setup writes the whole file. What each one uses:
| CI | Branch and commit | Where the key goes |
|---|---|---|
| GitHub Actions | github.head_ref or github.ref_name, github.sha | Repository secret LOGTHREAD_API_KEY |
| GitLab CI | CI_COMMIT_REF_NAME, CI_COMMIT_SHA (Docker-in-Docker for the scanner images) | Masked CI/CD variable LOGTHREAD_API_KEY |
| Azure DevOps | System.PullRequest.SourceBranch or Build.SourceBranch, Build.SourceVersion | Secret pipeline variable LOGTHREAD_API_KEY |
| Jenkins | BRANCH_NAME or GIT_BRANCH, GIT_COMMIT | Secret text credential logthread-api-key |
Uploads need curl 7.87 or later (for --url-query), which the hosted runners of all four have.
Troubleshooting#
- "First scan of this service, branch and tool" on every run: the
toolorbranchdiffers between runs. Pass the sametool=each time, and the branch name withoutrefs/heads/. - Everything is new on a pull request: the base branch has no full scan yet. Run the pipeline on
mainonce, or passbase_branch=. kind_required: the tool scans several kinds (Trivy). Addkind=.scan_quota: the plan's uploads per 24 hours are used. Merge reports per tool, or scan pull requests withpartial=trueand only changed files.
See also Send scan results to Logthread.