Use CloudBees platform’s security scanning features to maintain the security and integrity of your software assets. Configure your Jenkinsfile to run a security scan with a variety of popular tool types, including software composition analysis (SCA), static application security testing (SAST), and secret scanning. You can also set up automatic, implicit analysis of your integrated CI pipeline source code, ensuring that your software is continually assessed for vulnerabilities and risks.
Prerequisites
Set up CloudBees platform and your CI controller to work together. For more information, including technical requirements and limitations, refer to Getting started.
Set up security scanning on your Multibranch Pipeline
Set up your Jenkinsfile to install scanning tools, run scans, and publish security scan reports for ingestion to CloudBees platform, to leverage its enhanced analytics.
To enable security scan reports from your CI build to CloudBees platform:
| Scanning tool | Type |
|---|---|
Black Duck |
SCA |
Checkov |
SAST |
CodeQL |
SAST |
findsecbugs |
SAST |
Gitleaks |
Secrets |
Gosec |
SAST |
Grype |
SAST |
njsscanner |
SAST |
Snyk |
SAST |
Trivy |
Container |
SonarQube |
SAST |
JFrog |
SCA, Container |
Configure your Jenkinsfile to install, run, and publish scans
Use the registerSecurityScan step to indicate which Security Scan Result must be sent to CloudBees platform.
| Input name | Data type | Required? | Description |
|---|---|---|---|
|
String |
Yes |
Security scan to include. Wildcards are supported. |
|
String |
No |
|
|
String |
No |
If the |
|
String |
No |
Describes if the reports must also be archived in the Jenkins build. The default value is |
Example of a Pipeline stage including the step:
pipeline { stages { stage('Security Scan') { steps { registerSecurityScan( // Security Scan to include artifacts: "scan*", format: "sarif", scanner: "the-scanner", archive: true ) } } } }
Examples for scanners that support SARIF format
SARIF is a widely accepted standard used for sharing results from static analysis tools, especially in CI/CD environments.
The following examples illustrate how to use scanners that support SARIF format.
Black Duck sample Pipeline
Jenkinsfile example that uses the Black Duck scanner.
Add the following steps to your Jenkinsfile to install, run, and publish the results of a Black Duck scan to CloudBees platform.
| 1 | Download and extract Bridge CLI. Use Black Duck Bridge, not Black Duck Detect, for scanning. |
| 2 | Run the scan with SARIF output.
The shell command should be formed as above.
You must include blackducksca_reports_sarif_groupSCAIssues=false. |
| 3 | Check the SARIF report. |
Checkov sample Pipeline
Jenkinsfile example that uses the Checkov scanner.
Add the following steps to your Jenkinsfile to install, run, and publish the results of a Checkov scan to CloudBees platform.
| 1 | Install the scanner. |
| 2 | Run the scan. |
| 3 | Format the report in SARIF. |
Examples for scanners that do not support SARIF format
The following examples illustrate how to use scanners that do not support SARIF format.
Anchore sample Pipeline
Jenkinsfile example that uses the Anchore scanner.
Add the following steps to your Jenkinsfile to install, run, and publish the results of an Anchore scan to CloudBees platform.
SonarQube sample Pipeline
|
If you are using SonarQube and want to send results to your CloudBees platform instance, you must use the |
Jenkinsfile example that uses the SonarQube scanner.
Add the following steps to your Jenkinsfile to install, run, and publish the results of a SonarQube scan to CloudBees platform.
pipeline {
agent any
environment {
SONAR_HOST = "https://sonarqube.yourdomain.com"
PROJECT_KEY = "sarif__bash_test_${env.BUILD_NUMBER}"
SCANNER_VERSION = "5.0.1.3006"
SCANNER_HOME = "${WORKSPACE}/sonar-scanner-5.0.1.3006"
JAVA_HOME = "${WORKSPACE}/jdk17"
PATH = "${WORKSPACE}/jdk17/bin:${PATH}"
jq = "${WORKSPACE}/bin/jq"
}
stages {
stage('Install JDK') {
steps {
sh '''
echo "Downloading JDK..."
curl -sLo openjdk.tar.gz https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.14%2B7/OpenJDK17U-jdk_x64_linux_hotspot_17.0.14_7.tar.gz
tar -xzf openjdk.tar.gz
rm -rf jdk17 && mv jdk-17* jdk17
mkdir -p ${WORKSPACE}/bin
if [ ! -f ${WORKSPACE}/bin/jq ]; then
echo "Downloading jq..."
curl -sLo ${WORKSPACE}/bin/jq https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
chmod +x ${WORKSPACE}/bin/jq
fi
'''
}
}
stage('Install SonarScanner CLI') {
steps {
sh """
if [ ! -d "sonar-scanner-${SCANNER_VERSION}-linux" ]; then
echo "Downloading Sonar Scanner CLI..."
curl -sLo scanner-sq.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${SCANNER_VERSION}.zip
jar -xf scanner-sq.zip
rm scanner-sq.zip
else
echo "SonarScanner already installed."
fi
"""
}
}
stage('SonarQube Analysis') {
steps {
withCredentials([string(credentialsId: 'sonarqube-preprod-token', variable: 'SONAR_TOKEN')]) {
sh """
chmod +x ${SCANNER_HOME}/bin/sonar-scanner
${SCANNER_HOME}/bin/sonar-scanner \
-Dsonar.projectKey=$PROJECT_KEY \
-Dsonar.sources=. \
-Dsonar.host.url=$SONAR_HOST \
-Dsonar.login=$SONAR_TOKEN
"""
}
}
}
stage('Wait for Analysis') {
steps {
withCredentials([string(credentialsId: 'sonarqube-preprod-token', variable: 'SONAR_TOKEN')]) {
script {
def reportTask = readFile '.scannerwork/report-task.txt'
def ceTaskUrl = reportTask.readLines()
.find { it.startsWith("ceTaskUrl=") }
.replace("ceTaskUrl=", "")
echo "Waiting for SonarQube CE task to complete: ${ceTaskUrl}"
timeout(time: 5, unit: 'MINUTES') {
waitUntil {
def result = sh(
script: "curl -s -u ${SONAR_TOKEN}: ${ceTaskUrl} | $jq -r '.task.status'",
returnStdout: true
).trim()
echo "SonarQube CE task status: ${result}"
return (result == "SUCCESS")
}
}
}
}
}
}
stage('Export Sonar Findings') {
steps{
exportSonarQubeScan(
component: "",
project: "$PROJECT_KEY",
host: "$SONAR_HOST",
credentialId: "sonarqube-preprod-token"
)
}
}
}
}
Run an automatically triggered implicit scan of your source code
Implicit scanning in the CloudBees platform refers to the automatic security analysis of source code without requiring explicit user intervention. This process ensures continuous security checks by automatically triggering scans whenever certain events occur, such as:
-
The creation of a new component.
-
Committing changes in a connected repository.
-
Generating an artifact from a CI build.
Enable implicit security scanning to provide ongoing security monitoring.