Skip to content

Instantly share code, notes, and snippets.

@shaikkhajaibrahim
Created December 16, 2023 13:42
Show Gist options
  • Save shaikkhajaibrahim/dd9123db509f021ba1b6779c3fe8bb32 to your computer and use it in GitHub Desktop.
Save shaikkhajaibrahim/dd9123db509f021ba1b6779c3fe8bb32 to your computer and use it in GitHub Desktop.
pipeline {
agent { label 'docker' }
stages {
stage('clean workspace'){
steps{
cleanWs()
}
}
stage('Checkout from Git'){
steps{
git branch: 'main', url: 'https://github.com/KhajaWorkshopsAtQT/Dec1623.git'
}
}
stage('Build docker image') {
steps {
sh "docker image build -t shaikkhajaibrahim/jenkinsdec23workshop:$BUILD_ID ."
}
}
stage('Trivy Scan') {
steps {
script {
sh "trivy image --format json -o trivy-report.json shaikkhajaibrahim/jenkinsdec23workshop:$BUILD_ID"
}
publishHTML([reportName: 'Trivy Vulnerability Report', reportDir: '.', reportFiles: 'trivy-report.json', keepAll: true, alwaysLinkToLastBuild: true, allowMissing: false])
}
}
stage('publish docker image') {
steps {
sh "docker image push shaikkhajaibrahim/jenkinsdec23workshop:$BUILD_ID"
}
}
stage('Ensure kubernetes cluster is up') {
steps {
sh "cd deployment/terraform && terraform init && terraform apply -auto-approve"
}
}
stage('deploy to k8s') {
steps {
sh "kubectl apply -f deployment/k8s/deployment.yaml"
sh """
kubectl patch deployment netflix-app -p '{"spec":{"template":{"spec":{"containers":[{"name":"netflix-app","image":"shaikkhajaibrahim/jenkinsdec23workshop:$BUILD_ID"}]}}}}'
"""
}
}
stage('kubescape Scan') {
steps {
script {
sh "/home/ubuntu/.kubescape/bin/kubescape scan -t 40 deployment/k8s/deployment.yaml --format junit -o TEST-report.xml"
junit "**/TEST-*.xml"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment