CodeGuard

Bitbucket Pipelines

CodeGuard in Bitbucket Pipelines integrieren.

Bitbucket Pipelines

bitbucket-pipelines.yml:

image: mcr.microsoft.com/dotnet/sdk:9.0

pipelines:
  default:
    - step:
        name: CodeGuard
        caches:
          - codeguard
        script:
          - apt-get update -qq && apt-get install -qq -y unzip
          - curl -sSL -H "Authorization: Bearer $CODEGUARD_API_KEY" \
              -o codeguard.zip \
              https://codeguard.bochmann-software.com/api/v1/cli/1.4.0/linux-x64
          - unzip -q codeguard.zip -d /opt/codeguard
          - chmod +x /opt/codeguard/codeguard
          - export PATH="/opt/codeguard:$PATH"
          - codeguard analyze . --fail-on error --output console
        artifacts:
          - codeguard.sarif

definitions:
  caches:
    codeguard: ~/.cache/codeguard

API-Key

In Bitbucket: Repository settings → Repository variables, Variable CODEGUARD_API_KEY anlegen, "Secured" aktivieren.

PR-Annotations via Bitbucket Reports API

Optional könnt ihr die Findings als Bitbucket Code Insights posten. CodeGuard hat dafür keinen direkten Konverter, aber das JSON-Format ist gut handzuhaben:

- codeguard analyze . --output json --output-file findings.json
- # Wandle findings.json in Code-Insights-API-Calls um
- python3 ./scripts/publish-to-bitbucket-insights.py findings.json

Caching

Der caches: codeguard-Block oben mit der Custom-Cache-Definition unten persistiert ~/.cache/codeguard zwischen Pipelines.

Versions-Pinning

Wie immer empfohlen: konkrete CLI-Version pinnen, siehe Versionierung.