Skip to content
Open
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
185 changes: 75 additions & 110 deletions Jenkinsfile1
Original file line number Diff line number Diff line change
@@ -1,132 +1,97 @@
pipeline {
agent any
tools {
maven 'M3'
}
environment {
SCANNER_HOME = tool 'sonar-scanner'
maven 'M3'
git 'git'
}
stages {

stage('Git Checkout') {
steps {
echo 'Git Checkout'
git branch: 'main', credentialsId: 'git-cred', url: 'https://github.com/pythonkid2/FullStack-Blogging-App.git'
}
}
stage('Compile') {
steps {
sh 'mvn compile'
}
}
stage('Unit Testing') {
steps {
echo 'Running Unit Tests'
sh 'mvn test'
git branch: 'main', credentialsId: 'github-ssh-credentials', url: 'git@github.com:Muktamk/FullStack-Blogging-App.git'
}
}

stage('SonarQube Analysis') {
steps {
withSonarQubeEnv('sonar-server') {
sh ''' $SCANNER_HOME/bin/sonar-scanner \
-Dsonar.projectKey=Blogging-app \
-Dsonar.projectName=Blogging-app \
-Dsonar.java.binaries=target '''
}
}
}
stage('Trivy FS Scan') {
steps {
echo 'Running Trivy FS Scan'
sh 'trivy fs --format table -o fs-report.html .'
}
}
stage('Build') {
steps {
sh 'mvn package'
}
}
stage('Publish to Nexus') {
steps {
withMaven(globalMavenSettingsConfig: 'maven-settings', jdk: '', maven: 'M3', mavenSettingsConfig: '', traceability: true) {
sh 'mvn deploy'
}
}
}
stage('Build & Tag Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker build -t mjcmathew/blogging-app:latest .'
}
}
}
}
stage('Scan Docker Image with Trivy') {
steps {
echo 'Scanning Docker Image'
sh 'trivy image --format table -o image-report.html mjcmathew/blogging-app:latest'
}
}
stage('Push Docker Image') {
steps {
script {
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
sh 'docker push mjcmathew/blogging-app:latest'
}
}
}
}
stage('K8-Deployment') {


stage('Compile') {
steps {
echo 'Compiling the application using Maven'
sh 'mvn compile'
}
}

stage('Unit Testing') {
steps {
echo 'Running Unit Tests'
sh 'mvn test'
}
}

stage('Build') {
steps {
echo 'Building the application'
sh 'mvn package'
}
}

//stage('Publish to Nexus') {
// steps {
// withMaven(globalMavenSettingsConfig: '8922a16d-d9b3-4292-9d4c-84e6993d104a', maven: 'M3') {
// echo 'Deploying to Nexus'
// sh 'mvn deploy'
// }
// }
// }

stage('Build & Tag Docker Image') {
steps {
script {
// Ensure docker is configured correctly in Jenkins
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
echo 'Building Docker Image'
sh 'docker build -t mukta178/product-dev:latest .'
}
}
}
}

stage('Scan Docker Image with Trivy') {
steps {
echo 'Scanning Docker Image with Trivy'
sh 'trivy image --format table -o image-report.html mukta178/product-dev:latest'
}
}

stage('Push Docker Image') {
steps {
script {
// Ensure docker is configured correctly in Jenkins
withDockerRegistry(credentialsId: 'docker-cred', toolName: 'docker') {
echo 'Pushing Docker Image to registry'
sh 'docker push mukta178/product-dev:latest'
}
}
}
}

stage('K8-Deployment') {
steps {
withKubeConfig(caCertificate: '', clusterName: 'mega_project-cluster', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://B154517178067F3EE04A5D80589BEFD1.gr7.us-east-2.eks.amazonaws.com') {
withKubeConfig(caCertificate: '', clusterName: 'product-dev', contextName: '', credentialsId: 'k8-cred', namespace: 'sb-test', restrictKubeConfigAccess: false, serverUrl: 'https://0DB98FF44614C92E257E548E95115C01.sk1.us-east-2.eks.amazonaws.com') {
sh 'kubectl apply -f deployment-service.yml'
sleep 20
}
}
}
stage('Verify K8-Deployment') {
steps {
withKubeConfig(caCertificate: '', clusterName: 'mega_project-cluster', contextName: '', credentialsId: 'k8-cred', namespace: 'webapps', restrictKubeConfigAccess: false, serverUrl: 'https://B154517178067F3EE04A5D80589BEFD1.gr7.us-east-2.eks.amazonaws.com') {
sh 'kubectl get pods -n webapps'
sh 'kubectl get svc -n webapps'
withKubeConfig(caCertificate: '', clusterName: 'product-dev', contextName: '', credentialsId: 'k8-cred', namespace: 'sb-test', restrictKubeConfigAccess: false, serverUrl: 'https://0DB98FF44614C92E257E548E95115C01.sk1.us-east-2.eks.amazonaws.com') {
sh 'kubectl get pods -n sb-test'
sh 'kubectl get svc -n sb-test'
}
}
}

}
post {
always {
script {
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER
def pipelineStatus = currentBuild.result ?: 'UNKNOWN'
def bannerColor = pipelineStatus.toUpperCase() == 'SUCCESS' ? 'green' : 'red'

def body = """
<html>
<body>
<div style="border: 4px solid ${bannerColor}; padding: 10px;">
<h2>${jobName} - Build ${buildNumber}</h2>
<div style="background-color: ${bannerColor}; padding: 10px;">
<h3 style="color: white;">Pipeline Status: ${pipelineStatus.toUpperCase()}</h3>
</div>
<p>Check the <a href="${BUILD_URL}">console output</a>.</p>
</div>
</body>
</html>
"""

emailext (
subject: "${jobName} - Build ${buildNumber} - ${pipelineStatus.toUpperCase()}",
body: body,
to: 'mjcmathew@gmail.com',
from: 'jenkins@example.com',
replyTo: 'jenkins@example.com',
mimeType: 'text/html',
attachmentsPattern: 'trivy-image-report.html'
)
}
}
}
}

} // Closing the 'stages' block
} // Closing the 'pipeline' block