From ea3f84ae1f38b421bebc88e54f5cedefcb30fad5 Mon Sep 17 00:00:00 2001 From: Anuj Sharma Date: Tue, 9 Apr 2024 16:11:14 +0530 Subject: [PATCH 1/4] Update Jenkinsfile --- Jenkinsfile | 48 ++++++------------------------------------------ 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3e93a6e..e900806 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,43 +1,7 @@ -def containerName="springbootdocker" -def tag="latest" -def dockerHubUser="anujsharma1990" -def gitURL="https://github.com/anujdevopslearn/SpringBootDocker.git" +@Library(["JenkinsSharedLibrary@main"]) _ -node { - def sonarscanner = tool name: 'SonarQubeScanner', type: 'hudson.plugins.sonar.SonarRunnerInstallation' - stage('Checkout') { - checkout changelog: false, poll: false, scm: [$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: gitURL]]] - } - - stage('Build'){ - sh "mvn clean install" - } - - stage("Image Prune"){ - sh "docker image prune -f" - } - - stage('Image Build'){ - sh "docker build -t $containerName:$tag --pull --no-cache ." - echo "Image build complete" - } - - stage('Push to Docker Registry'){ - withCredentials([usernamePassword(credentialsId: 'dockerHubAccount', usernameVariable: 'dockerUser', passwordVariable: 'dockerPassword')]) { - sh "docker login -u $dockerUser -p $dockerPassword" - sh "docker tag $containerName:$tag $dockerUser/$containerName:$tag" - sh "docker push $dockerUser/$containerName:$tag" - echo "Image push complete" - } - } - - stage("SonarQube Scan"){ - withSonarQubeEnv(credentialsId: 'SonarQubeToken') { - sh "${sonarscanner}/bin/sonar-scanner" - } - } - - stage("Ansible Deploy"){ - ansiblePlaybook inventory: 'hosts', playbook: 'deploy.yaml' - } -} +mavenBuild( + gitURL = "https://github.com/anujdevopslearn/SpringBootDocker", + productType = "docker" + pomfileName = "pom.xml" +) From 6c23f6e98d7804d6a474b01cc92a2a528af7bf76 Mon Sep 17 00:00:00 2001 From: Anuj Sharma Date: Tue, 9 Apr 2024 16:19:28 +0530 Subject: [PATCH 2/4] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e900806..1354a9e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,7 +1,7 @@ @Library(["JenkinsSharedLibrary@main"]) _ mavenBuild( - gitURL = "https://github.com/anujdevopslearn/SpringBootDocker", - productType = "docker" - pomfileName = "pom.xml" + gitURL : "https://github.com/anujdevopslearn/SpringBootDocker", + productType : "docker", + pomfileName : "pom.xml" ) From 86c1ffa87edb3a43300a7cdcb3c02bd9d662bf4c Mon Sep 17 00:00:00 2001 From: Anuj Sharma Date: Tue, 9 Apr 2024 16:47:00 +0530 Subject: [PATCH 3/4] Update Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 1354a9e..ffbf659 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,4 +4,5 @@ mavenBuild( gitURL : "https://github.com/anujdevopslearn/SpringBootDocker", productType : "docker", pomfileName : "pom.xml" + containerName : "springboot-docker" ) From c4ef3d3c9bca6db049ad59a58b85447745219e10 Mon Sep 17 00:00:00 2001 From: Anuj Sharma Date: Tue, 9 Apr 2024 16:47:15 +0530 Subject: [PATCH 4/4] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ffbf659..636d357 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,6 +3,6 @@ mavenBuild( gitURL : "https://github.com/anujdevopslearn/SpringBootDocker", productType : "docker", - pomfileName : "pom.xml" + pomfileName : "pom.xml", containerName : "springboot-docker" )