Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-15736] Run Prisma Scan Pipeline also on Main Standalone Jar #15740

Merged
merged 7 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docker/prisma/Dockerfile.mainjars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM alpine:latest
COPY ./h2o-assemblies/main/build/libs/*.jar /tmp/
81 changes: 41 additions & 40 deletions scripts/jenkins/jenkinsfiles/Jenkinsfile-PrismaScan
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,42 @@
@Library('test-shared-library') _

def dockerImage
def branchOrTag
def steamImage

pipeline {
agent { node { label 'linux&&docker' } }
def setScanningStages(assemblyType, stageIndex) {
def assemblyImage
stage("${stageIndex}.A. Scan ${assemblyType} jar using Prisma") {
script {
branchName = "${env.BRANCH_NAME}".replace('/', '-')
assemblyImage = "h2o-assemblies/${assemblyType}:${BUILD_NUMBER}-${branchName}"

sh "docker build . -t ${assemblyImage} -f ./docker/prisma/Dockerfile.${assemblyType}jars"

parameters {
string(name: 'BRANCH_OR_TAG', defaultValue: 'master', description: 'Enter branch or tag you want to scan.')
// scan the image
prismaCloudScanImage ca: '',
cert: '',
dockerAddress: 'unix:///var/run/docker.sock',
image: "${assemblyImage}",
key: '',
logLevel: 'info',
podmanPath: '',
project: '',
resultsFile: "prisma-${assemblyType}-scan-results.json",
ignoreImageBuildTime: true
}
}
stage("${stageIndex}.B. Export results for ${assemblyType} jar to CSV") {
withCredentials([usernamePassword(credentialsId: 'twistlock_credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "curl -k -u \$USERNAME:\$PASSWORD https://mr-0xz1:8083/api/v1/scans/download?search=${assemblyImage} > ${assemblyImage}.csv"
}
archiveArtifacts artifacts: "${assemblyImage}.csv"
}
stage("${stageIndex}.C. Publish report for ${assemblyType} jar") {
prismaCloudPublish resultsFilePattern: "prisma-${assemblyType}-scan-results.json"
}
}

pipeline {
agent { node { label 'linux&&docker' } }

options {
ansiColor('xterm')
Expand All @@ -29,54 +56,28 @@ pipeline {

}
}
stage('1. Build jar') {
stage('1. Build jars') {
steps {
script{
dockerImage.inside(){
sh "./gradlew :h2o-assemblies:steam:shadowJar"
sh "./gradlew :h2o-assemblies:main:shadowJar"
archiveArtifacts artifacts: "h2o-assemblies/steam/build/libs/*.jar"
archiveArtifacts artifacts: "h2o-assemblies/main/build/libs/*.jar"
}
}
}
}
stage('2. Scan jar using Prisma'){
stage('2. Steam assembly jar') {
steps {
script{
branchOrTag = "${BRANCH_OR_TAG}".replace('/','-')
steamImage = "h2o-assemblies/steam:${BUILD_NUMBER}-${branchOrTag}"

sh "docker build . -t ${steamImage} -f ./docker/prisma/Dockerfile.scanningjars"

// scan the image
prismaCloudScanImage ca: '',
cert: '',
dockerAddress: 'unix:///var/run/docker.sock',
image: "${steamImage}",
key: '',
logLevel: 'info',
podmanPath: '',
project: '',
resultsFile: 'prisma-cloud-scan-results.json',
ignoreImageBuildTime:true
}

setScanningStages("steam", 2)
}
}
stage('3. Export results to CSV'){
steps{
withCredentials([usernamePassword(credentialsId: 'twistlock_credentials', usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD')]) {
sh "curl -k -u \$USERNAME:\$PASSWORD https://mr-0xz1:8083/api/v1/scans/download?search=${steamImage} > ${steamImage}.csv"
}
archiveArtifacts artifacts: "${steamImage}.csv"
}
}
stage('4. Publish report'){
steps{
prismaCloudPublish resultsFilePattern: 'prisma-cloud-scan-results.json'
stage('3. Main assembly jar') {
steps {
setScanningStages("main", 3)
}
}


}
post {
always {
Expand Down