diff --git a/Jenkinsfile b/Jenkinsfile index 80bed39d..0081d81a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,7 +9,12 @@ pipeline{ choice(name: 'action', choices: 'create\ndelete', description: 'Choose create/Destroy') string(name: 'ImageName', description: "name of the docker build", defaultValue: 'javapp') string(name: 'ImageTag', description: "tag of the docker build", defaultValue: 'v1') - string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'praveensingam1994') + string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'zeeshanmedlari') + } + + tools { + // Specify the Maven tool by name + maven 'Maven-3.9' } stages{ @@ -19,21 +24,21 @@ pipeline{ steps{ gitCheckout( branch: "main", - url: "https://github.com/praveen1994dec/Java_app_3.0.git" + url: "https://github.com/Zeeshanmedlari/Java_app_3.0.git" ) } } + stage('Unit Test maven'){ - when { expression { params.action == 'create' } } steps{ script{ - mvnTest() } } } + stage('Integration Test maven'){ when { expression { params.action == 'create' } } steps{ @@ -43,26 +48,29 @@ pipeline{ } } } + stage('Static code analysis: Sonarqube'){ when { expression { params.action == 'create' } } steps{ script{ - def SonarQubecredentialsId = 'sonarqube-api' + def SonarQubecredentialsId = 'Sonar_token' statiCodeAnalysis(SonarQubecredentialsId) } } } + stage('Quality Gate Status Check : Sonarqube'){ when { expression { params.action == 'create' } } steps{ script{ - def SonarQubecredentialsId = 'sonarqube-api' + def SonarQubecredentialsId = 'Sonar_token' QualityGateStatus(SonarQubecredentialsId) } } } + stage('Maven Build : maven'){ when { expression { params.action == 'create' } } steps{ @@ -72,6 +80,7 @@ pipeline{ } } } + stage('Docker Image Build'){ when { expression { params.action == 'create' } } steps{ @@ -81,15 +90,7 @@ pipeline{ } } } - stage('Docker Image Scan: trivy '){ - when { expression { params.action == 'create' } } - steps{ - script{ - - dockerImageScan("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") - } - } - } + stage('Docker Image Push : DockerHub '){ when { expression { params.action == 'create' } } steps{ @@ -99,6 +100,7 @@ pipeline{ } } } + stage('Docker Image Cleanup : DockerHub '){ when { expression { params.action == 'create' } } steps{ @@ -107,6 +109,7 @@ pipeline{ dockerImageCleanup("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") } } - } + } } } + diff --git a/Jenkinsfile_tst b/Jenkinsfile_tst new file mode 100644 index 00000000..e4a064b8 --- /dev/null +++ b/Jenkinsfile_tst @@ -0,0 +1,125 @@ +@Library('my-shared-library') _ + +pipeline{ + + agent any + + parameters{ + + choice(name: 'action', choices: 'create\ndelete', description: 'Choose create/Destroy') + string(name: 'ImageName', description: "name of the docker build", defaultValue: 'javapp') + string(name: 'ImageTag', description: "tag of the docker build", defaultValue: 'v1') + string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'zeeshanmedlari') + } + + tools { + // Specify the Maven tool by name + maven 'Maven-3.9' + } + + stages{ + + stage('Git Checkout'){ + when { expression { params.action == 'create' } } + steps{ + gitCheckout( + branch: "main", + url: "https://github.com/Zeeshanmedlari/Java_app_3.0.git" + ) + } + } + + stage('Unit Test maven'){ + when { expression { params.action == 'create' } } + + steps{ + script{ + mvnTest() + } + } + } + + stage('Integration Test maven'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + mvnIntegrationTest() + } + } + } + + stage('Static code analysis: Sonarqube'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + def SonarQubecredentialsId = 'SonarQube_server' + statiCodeAnalysis(SonarQubecredentialsId) + } + } + } + + stage('Quality Gate Status Check : Sonarqube'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + def SonarQubecredentialsId = 'Prime_SonarQube' + QualityGateStatus(SonarQubecredentialsId) + } + } + } + + stage('Maven Build : maven'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + mvnBuild() + } + } + } + + stage('Docker Image Build'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + dockerBuild("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } + } + } + + stage('Docker Image Scan: trivy '){ + when { expression { params.action == 'create' } } + steps{ + script{ + + dockerImageScan("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } + } + } + + stage('Docker Image Push : DockerHub '){ + when { expression { params.action == 'create' } } + steps{ + script{ + + dockerImagePush("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } + } + } + + stage('Docker Image Cleanup : DockerHub '){ + when { expression { params.action == 'create' } } + steps{ + script{ + + dockerImageCleanup("${params.ImageName}","${params.ImageTag}","${params.DockerHubUser}") + } + } + } + } +} +