Thursday, January 30, 2025

How to Setup AquaSec Trivy for Vulnerability scanning | How to scan Springboot Docker image using Trivy Scanner | Create Jenkins Pipeline for scanning Docker image for Springboot Microservices App

Watch steps in YouTube channel:

Pre-requisites:

Jenkins Pipeline for scanning docker image using Trivy scanner:

pipeline {
    agent any
    environment {
        registry = "acct_id.dkr.ecr.us-east-1.amazonaws.com/coachak/springboot-app"
    }

    stages {
        stage('Checkout') {
            steps {
                git 'https://github.com/akannan1087/docker-spring-boot'
            }
        }
        
        stage ("Build JAR") {
            steps {
                sh "mvn clean install"
            }
        }
        
        stage ("Build image") {
            steps {
                script {
                    dockerImage = docker.build registry
                    dockerImage.tag("$BUILD_NUMBER")
                }
            }
        }
        
    // Scanning Docker images using Trivy scanner
     stage('Trivy Security scan') {
     steps{
         script {
            sh "trivy image --severity HIGH,CRITICAL,MEDIUM acct_id.dkr.ecr.us-east-1.amazonaws.com/coachak/springboot-app:$BUILD_NUMBER"
         }
      }
     }
    // Uploading Docker images into AWS ECR
    stage('Pushing to ECR') {
     steps{  
         script {
                sh 'aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin acct_id.dkr.ecr.us-east-1.amazonaws.com'
                sh 'docker push acct_id.dkr.ecr.us-east-1.amazonaws.com/coachak/springboot-app:$BUILD_NUMBER'
         }
        }
     }
    }
}

Pipeline Output:




Scan report can be viewed in Jenkins


No comments:

Post a Comment

How to create Ubuntu 22.0.4 Virtual Machine (VM) in Azure? | Create Ubuntu 22.0.4 VM in Azure | How to connect to Azure VM from your local machine

 How to Create Ubuntu 22.0.4 Virtual Machines(VM) in Azure portal? Creating Virtual Machine is easy and straight forward in Azure Cloud. Let...