diff --git a/Jenkinsfile b/Jenkinsfile old mode 100644 new mode 100755 index 3392428c..c10b5e14 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,14 +3,14 @@ pipeline{ agent any - //agent { label 'Demo' } + //agent { label 'Demo' } 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: 'praveensingam1994') + string(name: 'DockerHubUser', description: "name of the Application", defaultValue: 'rupamn11') } stages{ @@ -20,7 +20,7 @@ pipeline{ steps{ gitCheckout( branch: "main", - url: "https://github.com/praveen1994dec/Java_app_3.0.git" + url: "https://github.com/rupamn11/Java_app_3.0.git" ) } } diff --git a/Jenkinsfileman b/Jenkinsfileman new file mode 100755 index 00000000..786fcece --- /dev/null +++ b/Jenkinsfileman @@ -0,0 +1,135 @@ +@Library('my-shared-library') _ + +pipeline{ + + agent any + //agent { label 'Demo' } + + 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: 'rupamn11') + } + + stages{ + + stage('Git Checkout'){ + when { expression { params.action == 'create' } } + steps{ + gitCheckout( + branch: "main", + url: "https://github.com/rupamn11/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-api' + statiCodeAnalysis(SonarQubecredentialsId) + } + } + } + stage('Quality Gate Status Check : Sonarqube'){ + when { expression { params.action == 'create' } } + steps{ + script{ + + def SonarQubecredentialsId = 'sonarqube-api' + 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}") +// } +// } +// } + stage('Update K8s Manifest Repo for ArgoCD') { + when { expression { params.action == 'create' } } + steps { + script { + dir('k8s-manifests-repo') { + git credentialsId: 'github-creds', branch: 'main', url: 'https://github.com/rupamn11/k8s-manifests-repo.git' + + sh """ + sed -i 's|image: ${params.DockerHubUser}/${params.ImageName}:.*|image: ${params.DockerHubUser}/${params.ImageName}:${params.ImageTag}|' deployment.yaml + """ + + sh """ + git config user.email "rupamnimje147@gmail.com" + git config user.name "rupamn11" + git add deployment.yaml + git commit -m "Update image to ${params.DockerHubUser}/${params.ImageName}:${params.ImageTag}" + git push origin main + """ + } + } + } + } + } +}