|
| 1 | +# ScanCode.io Jenkins Integration |
| 2 | + |
| 3 | +Run [ScanCode.io](https://github.com/aboutcode-org/scancode.io) into your Jenkins CI/CD |
| 4 | +pipeline. |
| 5 | + |
| 6 | +- [Overview](#overview) |
| 7 | +- [Prerequisites](#prerequisites) |
| 8 | +- [Quick Start](#quick-start) |
| 9 | +- [Simple Example](#simple-example) |
| 10 | +- [Specify Pipeline](#specify-pipeline) |
| 11 | +- [Additional Resources](#additional-resources) |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Overview |
| 16 | + |
| 17 | +This integration allows you to automatically scan your code as part of your Jenkins |
| 18 | +pipeline: |
| 19 | + |
| 20 | +- Scans your entire codebase using ScanCode.io |
| 21 | +- Generates a comprehensive JSON report |
| 22 | +- Archives the results as Jenkins build artifacts |
| 23 | +- Runs automatically on every build |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +Before you begin, ensure you have: |
| 28 | + |
| 29 | +1. **Jenkins installed and running** |
| 30 | + - Version 2.x or higher recommended |
| 31 | + |
| 32 | +2. **Docker installed on your Jenkins agent** |
| 33 | + - Docker must be accessible to Jenkins |
| 34 | + - Test with: `docker --version` |
| 35 | + |
| 36 | +3. **Required Jenkins Plugins**: |
| 37 | + - Docker Pipeline Plugin |
| 38 | + - Pipeline Plugin |
| 39 | + - Git Plugin (if using Git) |
| 40 | + |
| 41 | +## Quick Start |
| 42 | + |
| 43 | +### Step 1: Create a Jenkinsfile |
| 44 | + |
| 45 | +Create a file named `Jenkinsfile` in the root of your repository with the following |
| 46 | +content: |
| 47 | + |
| 48 | +```groovy |
| 49 | +pipeline { |
| 50 | + agent any |
| 51 | + |
| 52 | + stages { |
| 53 | + stage('ScanCode.io Scan') { |
| 54 | + steps { |
| 55 | + echo 'Running ScanCode.io scan...' |
| 56 | + |
| 57 | + sh ''' |
| 58 | + docker run --rm \ |
| 59 | + -v "${WORKSPACE}":/codedrop \ |
| 60 | + ghcr.io/aboutcode-org/scancode.io:latest \ |
| 61 | + run scan_codebase /codedrop \ |
| 62 | + > scancode_results.json |
| 63 | + ''' |
| 64 | + |
| 65 | + echo 'Scan completed!' |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + stage('Archive Results') { |
| 70 | + steps { |
| 71 | + archiveArtifacts artifacts: 'scancode_results.json', fingerprint: true |
| 72 | + echo 'Results archived successfully' |
| 73 | + } |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +### Step 3: Access Your Results |
| 80 | + |
| 81 | +After the build completes: |
| 82 | +1. Go to the build page |
| 83 | +2. Click on "Build Artifacts" |
| 84 | +3. Download `scancode_results.json` |
| 85 | + |
| 86 | +## Simple Example |
| 87 | + |
| 88 | +```groovy |
| 89 | +pipeline { |
| 90 | + agent any |
| 91 | + |
| 92 | + stages { |
| 93 | + stage('Scan') { |
| 94 | + steps { |
| 95 | + sh ''' |
| 96 | + docker run --rm \ |
| 97 | + -v "${WORKSPACE}":/codedrop \ |
| 98 | + ghcr.io/aboutcode-org/scancode.io:latest \ |
| 99 | + run scan_codebase /codedrop \ |
| 100 | + > scancode_results.json |
| 101 | + ''' |
| 102 | + archiveArtifacts 'scancode_results.json' |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +This minimal example: |
| 110 | +- Runs the scan in a single stage |
| 111 | +- Archives the results |
| 112 | + |
| 113 | +## Specify Pipeline |
| 114 | + |
| 115 | +Instead of `scan_codebase`, you can use other ScanCode.io pipelines: |
| 116 | + |
| 117 | +- `scan_single_package` - For scanning a single package |
| 118 | +- `analyse_docker_image` - For scanning Docker images |
| 119 | +- `load_inventory` - For loading existing scan data |
| 120 | + |
| 121 | +Example with a different pipeline: |
| 122 | +```groovy |
| 123 | +sh ''' |
| 124 | + docker run --rm \ |
| 125 | + -v "${WORKSPACE}":/codedrop \ |
| 126 | + ghcr.io/aboutcode-org/scancode.io:latest \ |
| 127 | + run analyse_docker_image docker://alpine:3.22.1 \ |
| 128 | + > scancode_results.json |
| 129 | +''' |
| 130 | +``` |
| 131 | + |
| 132 | +## Additional Resources |
| 133 | + |
| 134 | +- **ScanCode.io Documentation:** https://scancodeio.readthedocs.io/ |
| 135 | +- **ScanCode.io GitHub:** https://github.com/aboutcode-org/scancode.io |
| 136 | +- **Jenkins Pipeline Documentation:** https://www.jenkins.io/doc/book/pipeline/ |
0 commit comments