CI/CD
GitLab CI Integration
Add a GauntletCI job to your .gitlab-ci.yml to analyze every merge request diff and block high-risk changes from merging.
Basic setup
Add this job to your .gitlab-ci.yml. It runs only on merge request pipelines using the official Microsoft .NET SDK Docker image:
gauntletci-analysis:
image: mcr.microsoft.com/dotnet/sdk:8.0
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet tool install -g GauntletCI
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD > pr.diff
- gauntletci analyze --diff pr.diff --no-banner --ascii
allow_failure: false$CI_MERGE_REQUEST_TARGET_BRANCH_NAMEis set automatically by GitLab on MR pipelines.allow_failure: falsemarks the MR pipeline as failed if findings are detected.- The
--asciiflag prevents Unicode box-drawing characters from corrupting the job log.
Advisory mode
To report findings without blocking the merge, set allow_failure: true:
gauntletci-analysis:
image: mcr.microsoft.com/dotnet/sdk:8.0
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet tool install -g GauntletCI
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD > pr.diff
- gauntletci analyze --diff pr.diff --no-banner --ascii
allow_failure: true # findings reported but MR not blockedSave findings as a pipeline artifact
Use --output json to write a structured report and upload it as a GitLab artifact:
gauntletci-analysis:
image: mcr.microsoft.com/dotnet/sdk:8.0
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- export PATH="$PATH:$HOME/.dotnet/tools"
- dotnet tool install -g GauntletCI
- git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_NAME
- git diff origin/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME...HEAD > pr.diff
- gauntletci analyze --diff pr.diff --output json --no-banner > gauntletci-report.json
artifacts:
paths:
- gauntletci-report.json
expire_in: 7 days
allow_failure: falseThe artifact is available under Browse artifacts on the pipeline job page and can be downloaded or used by downstream jobs.
Pipeline mockup
A failed gauntletci-analysis job blocks the merge button when GitLab is configured with a required pipeline status rule.
Sensitivity configuration
Pass --sensitivity to control which findings are reported. You can also set it via a CI/CD variable so different branches use different levels:
- gauntletci analyze --diff pr.diff \
--sensitivity ${GAUNTLETCI_SENSITIVITY:-balanced} \
--no-banner --asciiSet GAUNTLETCI_SENSITIVITY as a GitLab CI/CD variable under Settings > CI/CD > Variables. Defaults to balanced if unset.
