How do you add ZAP to a CI/CD pipeline?

IntermediateHands-onOWASP ZAP
Answer

Short answer

Run ZAP after deploying to staging (or an ephemeral PR environment): a baseline scan on every deployment, and full/API scans on a schedule. Use a rules file so only agreed findings fail the build, publish the report as an artifact, and optionally open issues automatically.

GitHub Actions

jobs:
  deploy-staging:
    # ... deploys to https://staging.shop.example.com
  dast:
    needs: deploy-staging
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: ZAP baseline
        uses: zaproxy/[email protected]
        with:
          target: https://staging.shop.example.com
          rules_file_name: .zap/rules.tsv
          cmd_options: '-a'
          fail_action: true

Jenkins

stage('DAST') {
  steps {
    sh '''
      docker run --rm -v $WORKSPACE/zap:/zap/wrk:rw ghcr.io/zaproxy/zaproxy:stable \
        zap-baseline.py -t https://staging.shop.example.com -c rules.tsv -r zap.html
    '''
  }
  post { always { publishHTML(target: [reportDir: 'zap', reportFiles: 'zap.html', reportName: 'ZAP']) } }
}

Rules file (.zap/rules.tsv)

10038	FAIL	(CSP header not set)
10020	FAIL	(Anti-clickjacking header missing)
10096	IGNORE	(Timestamp disclosure - false positive on build IDs)

What to say in the interview

"ZAP runs right after the staging deployment — baseline on every release with a rules file that defines what fails — and nightly full or API scans. Reports are published as artifacts, and DAST never runs against production unless explicitly agreed."

All Security Tools questions Roadmap: OWASP ZAP — dynamic testing (DAST)

More on OWASP ZAP