diff --git a/Jenkinsfile1 b/Jenkinsfile1 index df893d1..6acc014 100644 --- a/Jenkinsfile1 +++ b/Jenkinsfile1 @@ -1,85 +1,84 @@ 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 } @@ -87,46 +86,12 @@ pipeline { } 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 = """ - -
-Check the console output.
-