Azure DevOps Pipelines
CodeGuard läuft in Azure Pipelines als Shell-Step. Robust, einfach zu pinnen, ohne externe Abhängigkeiten ausser dem CLI-Download.
Minimal-Setup
azure-pipelines.yml:
trigger:
branches:
include: [main]
pr:
branches:
include: [main]
pool:
vmImage: ubuntu-latest
variables:
CODEGUARD_VERSION: '1.4.0'
steps:
- task: UseDotNet@2
inputs:
version: '9.0.x'
- bash: |
curl -sSL -H "Authorization: Bearer $(CODEGUARD_API_KEY)" \
-o codeguard.zip \
https://codeguard.bochmann-software.com/api/v1/cli/$(CODEGUARD_VERSION)/linux-x64
unzip -q codeguard.zip -d /opt/codeguard
chmod +x /opt/codeguard/codeguard
echo "##vso[task.prependpath]/opt/codeguard"
displayName: 'Install CodeGuard CLI'
env:
CODEGUARD_API_KEY: $(CodeGuardApiKey)
- bash: |
codeguard analyze . --fail-on error --output sarif --output-file codeguard.sarif
displayName: 'Run CodeGuard'
- task: PublishBuildArtifacts@1
condition: always()
inputs:
pathToPublish: codeguard.sarif
artifactName: codeguard-sarif
API-Key in Pipeline-Secret
- Im Portal unter API Keys einen Key erzeugen.
- In Azure DevOps:
Pipelines → Library → Variable groups → New, VariableCodeGuardApiKeymit Wert anlegen, Lock-Icon klicken (macht sie zum Secret). - In der Pipeline-YAML auf die Variable referenzieren wie oben gezeigt.
SARIF anzeigen
Azure DevOps hat keinen nativen SARIF-Viewer. Zwei gute Optionen:
Option A. SARIF-Viewer-Extension
Es gibt eine SARIF SAST Scans Tab Marketplace-Extension. Nach der Installation taucht ein "Scans"-Tab neben Tests und Code Coverage auf, der SARIF-Artifacts rendert.
Option B. Markdown-Report
- bash: |
codeguard analyze . --output console --output-file codeguard-report.txt
echo "##vso[task.uploadsummary]$PWD/codeguard-report.txt"
displayName: 'Publish CodeGuard summary'
uploadsummary hängt den Text an die Build-Summary an. Kein hübsches
UI, aber sichtbar.
Caching
Azure Pipelines hat Cache@2:
- task: Cache@2
inputs:
key: 'codeguard | "$(Agent.OS)" | .codeguard/**/* | **/*.csproj'
path: $(Pipeline.Workspace)/.cache/codeguard
displayName: 'Cache CodeGuard'
- bash: codeguard analyze . --fail-on error
env:
CODEGUARD_CACHE_DIR: $(Pipeline.Workspace)/.cache/codeguard
Self-Hosted Agents
Funktioniert ohne Anpassungen. Der Agent braucht Netzzugriff auf
codeguard.bochmann-software.com oder ihr spiegelt das CLI-Binary in
euer eigenes Artifact-Feed.