Jenkins Plugin
Integrate CXRay security scanning into your Jenkins CI/CD pipelines.
Installation
Via Jenkins Plugin Manager
- Navigate to Manage Jenkins → Manage Plugins
- Go to the Available tab
- Search for "CXRay Security Scanner"
- Select the plugin and click Install without restart
Manual Installation
- Download the latest
.hpifile from the CXRay Jenkins Plugin releases - Navigate to Manage Jenkins → Manage Plugins → Advanced
- Upload the
.hpifile under Upload Plugin - Restart Jenkins when safe
Configuration
Global Configuration
- Go to Manage Jenkins → Configure System
- Scroll to CXRay Configuration
- Configure the following settings:
CXRay API URL: https://api.cxray.io
API Key: [Your API Key]
Database Update Frequency: Daily
Credentials Setup
Store your CXRay API key securely:
- Navigate to Manage Jenkins → Manage Credentials
- Add a Secret text credential
- Enter your CXRay API key
- Set ID as
cxray-api-key
Pipeline Integration
Declarative Pipeline
pipeline {
agent any
stages {
stage('Checkout') {
steps {
checkout scm
}
}
stage('Build') {
steps {
sh 'npm install'
sh 'npm run build'
}
}
stage('CXRay Security Scan') {
steps {
cxrayScan(
scanTypes: ['cve', 'cce', 'sbom'],
severity: 'high,critical',
failOnSeverity: 'critical',
outputFormat: 'json',
generateReport: true
)
}
}
}
post {
always {
// Archive scan results
archiveArtifacts artifacts: 'cxray-*.json', allowEmptyArchive: true
// Publish HTML report
publishHTML([
reportDir: 'cxray-reports',
reportFiles: 'index.html',
reportName: 'CXRay Security Report'
])
}
}
}
Scripted Pipeline
node {
stage('Checkout') {
checkout scm
}
stage('Build') {
sh 'npm install'
sh 'npm run build'
}
stage('CXRay Scan') {
def scanResult = cxrayScan(
scanTypes: ['cve', 'sbom'],
severity: 'all',
outputFormat: 'json'
)
// Check scan results
if (scanResult.criticalCount > 0) {
error("Critical vulnerabilities found: ${scanResult.criticalCount}")
}
}
}
Freestyle Project
- Create or configure a Freestyle project
- Add a Build Step → CXRay Security Scan
- Configure scan options:
Scan Types: CVE, CCE, SBOM
Severity Filter: high,critical
Fail Build On: critical
Output Format: JSON
Generate HTML Report: Yes
Configuration Options
Scan Types
- CVE: Vulnerability scanning
- CCE: Configuration scanning
- SBOM: Software Bill of Materials generation
Severity Filters
all: All severitiescritical: Critical onlyhigh,critical: High and Criticalmedium,high,critical: Medium and above
Fail Conditions
Configure when the build should fail:
cxrayScan(
failOnSeverity: 'critical', // Fail on critical findings
failOnCVSS: 9.0, // Fail on CVSS >= 9.0
failOnCount: [critical: 1, high: 5] // Fail on count thresholds
)
Advanced Features
Scan Specific Paths
cxrayScan(
scanPath: 'src/',
excludePaths: ['node_modules/', 'test/']
)
Custom Configuration
cxrayScan(
configFile: 'custom-cxray.yml',
customRules: 'jenkins-rules/'
)
Differential Scanning
Only scan changed files:
cxrayScan(
differential: true,
baseCommit: env.GIT_PREVIOUS_COMMIT
)
Report Generation
HTML Report
cxrayScan(
generateReport: true,
reportFormat: 'html',
reportOutput: 'cxray-report/'
)
publishHTML([
reportDir: 'cxray-report',
reportFiles: 'index.html',
reportName: 'CXRay Security Report',
keepAll: true
])
SARIF for GitHub Integration
cxrayScan(
outputFormat: 'sarif',
reportOutput: 'results.sarif'
)
// Upload to GitHub Code Scanning
sh 'gh api repos/${REPO}/code-scanning/sarifs -f sarif=@results.sarif'
Multiple Output Formats
cxrayScan(
outputs: [
[format: 'json', file: 'cxray.json'],
[format: 'html', file: 'report.html'],
[format: 'sarif', file: 'results.sarif'],
[format: 'csv', file: 'findings.csv']
]
)
Notifications
Email Notifications
post {
failure {
emailext(
subject: "CXRay Scan Failed: ${env.JOB_NAME}",
body: "Critical vulnerabilities found in build ${env.BUILD_NUMBER}",
to: 'security-team@example.com',
attachmentsPattern: 'cxray-report.html'
)
}
}
Slack Notifications
post {
always {
script {
def scanResult = readJSON file: 'cxray-results.json'
slackSend(
channel: '#security-alerts',
color: scanResult.criticalCount > 0 ? 'danger' : 'good',
message: "CXRay Scan: ${scanResult.criticalCount} critical, ${scanResult.highCount} high vulnerabilities"
)
}
}
}
Troubleshooting
Plugin Not Scanning
Check the following:
- API key is correctly configured
- Network connectivity to CXRay API
- Sufficient disk space for database
- Project contains supported package managers
Build Failing Unexpectedly
// Add verbose logging
cxrayScan(
verbose: true,
logLevel: 'debug'
)
Database Update Issues
Force database update:
cxrayScan(
updateDatabase: true,
forceUpdate: true
)
Best Practices
- Run Early: Execute CXRay scans early in the pipeline
- Cache Database: Cache the vulnerability database between builds
- Set Thresholds: Define clear failure thresholds
- Archive Results: Always archive scan results as artifacts
- Monitor Trends: Track vulnerability trends over time
- Incremental Scans: Use differential scanning for large projects