|
| 1 | +# ScanCode.io GitLab CI/CD Integration |
| 2 | + |
| 3 | +Run [ScanCode.io](https://github.com/aboutcode-org/scancode.io) into your GitLab CI/CD |
| 4 | +pipeline. |
| 5 | + |
| 6 | +- [Overview](#overview) |
| 7 | +- [Quick Start](#quick-start) |
| 8 | +- [Specify Pipeline](#specify-pipeline) |
| 9 | +- [Additional Resources](#additional-resources) |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## Overview |
| 14 | + |
| 15 | +This integration allows you to automatically scan your code as part of your GitLab |
| 16 | +pipeline: |
| 17 | + |
| 18 | +- Scans your entire codebase using ScanCode.io |
| 19 | +- Generates a comprehensive JSON report |
| 20 | +- Archives the results as GitLab pipeline artifacts |
| 21 | +- Runs automatically on every build |
| 22 | + |
| 23 | +## Quick Start |
| 24 | + |
| 25 | +### Step 1: Create a .gitlab-ci.yml file |
| 26 | + |
| 27 | +Create a file named `.gitlab-ci.yml` in the root of your repository with the following |
| 28 | +content: |
| 29 | + |
| 30 | +```yaml |
| 31 | +# GitLab CI/CD Pipeline with ScanCode.io Integration |
| 32 | + |
| 33 | +stages: |
| 34 | + - scan |
| 35 | + |
| 36 | +# ScanCode.io Scan Job |
| 37 | +scancode_scan: |
| 38 | + stage: scan |
| 39 | + image: docker:latest |
| 40 | + services: |
| 41 | + - docker:dind |
| 42 | + variables: |
| 43 | + DOCKER_DRIVER: overlay2 |
| 44 | + DOCKER_TLS_CERTDIR: "/certs" |
| 45 | + script: |
| 46 | + - echo "Running ScanCode.io scan..." |
| 47 | + |
| 48 | + # Run the scan and save results |
| 49 | + - | |
| 50 | + docker run --rm \ |
| 51 | + -v "$(pwd)":/codedrop \ |
| 52 | + ghcr.io/aboutcode-org/scancode.io:latest \ |
| 53 | + run scan_codebase /codedrop \ |
| 54 | + > scancode_results.json |
| 55 | + |
| 56 | + - echo "Scan completed!" |
| 57 | + |
| 58 | + artifacts: |
| 59 | + name: "scancode-results-${CI_COMMIT_SHORT_SHA}" |
| 60 | + paths: |
| 61 | + - scancode_results.json |
| 62 | + expire_in: 30 days |
| 63 | + when: always |
| 64 | +``` |
| 65 | +
|
| 66 | +### Step 2: Access Your Results |
| 67 | +
|
| 68 | +After the pipeline completes: |
| 69 | +1. Go to your pipeline page |
| 70 | +2. Click on the job name (`scancode_scan`) |
| 71 | +3. On the right sidebar, click "Browse" under "Job artifacts" |
| 72 | +4. Download `scancode_results.json` |
| 73 | + |
| 74 | +Or download directly from the pipeline page using the download button. |
| 75 | + |
| 76 | +## Specify Pipeline |
| 77 | + |
| 78 | +Instead of `scan_codebase`, you can use other ScanCode.io pipelines: |
| 79 | + |
| 80 | +- `scan_single_package` - For scanning a single package |
| 81 | +- `analyse_docker_image` - For scanning Docker images |
| 82 | +- `load_inventory` - For loading existing scan data |
| 83 | + |
| 84 | +Example with a different pipeline: |
| 85 | +```yaml |
| 86 | +script: |
| 87 | + - | |
| 88 | + docker run --rm \ |
| 89 | + -v "$(pwd)":/codedrop \ |
| 90 | + ghcr.io/aboutcode-org/scancode.io:latest \ |
| 91 | + run analyse_docker_image docker://alpine:3.22.1 \ |
| 92 | + > scancode_results.json |
| 93 | +``` |
| 94 | + |
| 95 | +## Additional Resources |
| 96 | + |
| 97 | +- **ScanCode.io Documentation:** https://scancodeio.readthedocs.io/ |
| 98 | +- **ScanCode.io GitHub:** https://github.com/aboutcode-org/scancode.io |
| 99 | +- **GitLab CI/CD Documentation:** https://docs.gitlab.com/ee/ci/ |
0 commit comments