Skip to content

GitLab CI Integration

SCC CLI integrates with GitLab CI/CD for automated configuration validation and AI coding governance.

.gitlab-ci.yml
stages:
- validate
scc-validate:
stage: validate
image: python:3.12
script:
- curl -LsSf https://astral.sh/uv/install.sh | sh
- export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
- uv tool install scc-cli
- scc setup --org "$SCC_ORG_SOURCE" --auth env:SCC_ORG_TOKEN --team ci --non-interactive
- scc start --dry-run --json --non-interactive --team ci .
variables:
SCC_ORG_SOURCE: $SCC_ORG_SOURCE
SCC_ORG_TOKEN: $SCC_ORG_TOKEN

Add these variables in Settings → CI/CD → Variables:

VariableDescriptionSettings
SCC_ORG_SOURCEURL or shorthand for your org configProtected
SCC_ORG_TOKENAuth token for private configsMasked, Protected
scc-validate:
stage: validate
image: python:3.12
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- .scc.yaml
- team-config.json
script:
- pip install scc-cli
- scc team validate --file team-config.json
validate-team-config:
stage: validate
image: python:3.12
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- team-config.json
script:
- pip install scc-cli
- scc team validate --file team-config.json
artifacts:
reports:
dotenv: scc-validation.env
plugin-audit:
stage: audit
image: python:3.12
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
script:
- pip install scc-cli
- scc setup --org "$SCC_ORG_SOURCE" --non-interactive
- scc audit plugins --json > plugin-audit.json
artifacts:
paths:
- plugin-audit.json
expire_in: 30 days

Speed up pipelines by caching SCC configuration:

scc-validate:
stage: validate
image: python:3.12
cache:
key: scc-cache
paths:
- ~/.cache/scc/
script:
- pip install scc-cli
- scc setup --org "$SCC_ORG_SOURCE" --non-interactive
- scc start --dry-run --non-interactive --team ci .

SCC exit codes map to GitLab job status:

CodeMeaningJob Status
0SuccessPassed
2Usage errorFailed
3Configuration errorFailed
6Governance blockFailed

Handle specific failures:

scc-validate:
script:
- pip install scc-cli
- |
scc start --dry-run --non-interactive --team ci .
exit_code=$?
if [ $exit_code -eq 6 ]; then
echo "Configuration blocked by governance policy"
exit 1
fi

Create a minimal profile for GitLab CI:

{
"profiles": {
"ci": {
"description": "GitLab CI pipeline profile",
"additional_plugins": [],
"session": {
"timeout_hours": 1
},
"network_policy": "isolated"
}
}
}

For running actual SCC sessions (not just validation):

scc-session:
stage: test
image: docker:24-dind
services:
- docker:24-dind
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- apk add --no-cache python3 py3-pip
- pip install scc-cli
script:
- scc setup --org "$SCC_ORG_SOURCE" --non-interactive
- scc start --non-interactive --team ci .
  • Use protected variables: Restrict access to protected branches
  • Mask tokens: Prevent secrets from appearing in logs
  • Minimal profiles: CI profiles should be restrictive
  • Review MR changes: Validate config changes before merge

Ensure PATH includes the installation directory:

script:
- pip install scc-cli
- export PATH="$HOME/.local/bin:$PATH"
- scc --version

For dry-run validation, Docker isn’t required. For sessions, use Docker-in-Docker service or a shell executor with Docker.

Ensure CI/CD variables are defined and not limited to protected branches if running on feature branches.