From 15a612ca92592754fe2b4910900cde3ad3bb2251 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 27 Jun 2024 11:20:50 +0530 Subject: [PATCH 01/54] Update pom.xml --- pom.xml | 110 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/pom.xml b/pom.xml index 01e0d5a2..e4ec50b6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,51 +1,65 @@ - 4.0.0 - in.RAHAM - NETFLIX - war - 1.2.2 - Java Home myweb - http://maven.apache.org - - - kammana - - - - com.oracle.bedrock - bedrock-runtime-maven - 5.1.2 - - - - junit - junit - 3.8.1 - test - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + in.RAHAM + NETFLIX + war + 1.2.2 + Java Home myweb + http://maven.apache.org + + + kammana + 1.8 + 1.8 + + + + + com.oracle.bedrock + bedrock-runtime-maven + 5.1.2 + + + + junit + junit + 3.8.1 + test + + + + + + nexusRepo + http://13.233.230.166:8081/repository/maven-snapshots/ + + + + nexusRepo + http://13.233.230.166:8081/repository/maven-releases/ + + + + + + maven1 + Maven.org + http://repo1.maven.org/maven2 + + - - - - - nexusRepo - http://13.233.230.166:8081/repository/maven-snapshots/ - - - - nexusRepo - http://13.233.230.166:8081/repository/maven-releases/ - - - - - - maven1 - Maven.org - http://repo1.maven.org/maven2 - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${maven.compiler.source} + ${maven.compiler.target} + + + + From dcbcd139a5f08a206d8056daa675a84799c047d7 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Wed, 3 Jul 2024 11:05:40 +0530 Subject: [PATCH 02/54] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e4ec50b6..604d9977 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 in.RAHAM - NETFLIX + JAVA_APP war 1.2.2 Java Home myweb From c4f355c9498192879d46802c3691dde2105560fc Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:29:09 +0530 Subject: [PATCH 03/54] Update pom.xml --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 604d9977..84b9cd63 100644 --- a/pom.xml +++ b/pom.xml @@ -43,9 +43,8 @@ - maven1 - Maven.org - http://repo1.maven.org/maven2 + central + https://repo.maven.apache.org/maven2 From b9acc82931a1504c9d834c81018c90a8331002d4 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:30:35 +0530 Subject: [PATCH 04/54] Update pom.xml From 3e65169c77aa3261ed2a3f7e7d1a8c563c1c0aa2 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 10:35:46 +0530 Subject: [PATCH 05/54] Update pom.xml From d69e652e077c390b35503f01398764568de7a48a Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:07:49 +0530 Subject: [PATCH 06/54] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 84b9cd63..f42f7e65 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.2 + 1.2 Java Home myweb http://maven.apache.org From 98e60e50c01b7fe17b1fe135f14eba787dfb46df Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 08:49:07 +0000 Subject: [PATCH 07/54] Update version to 1.2.47 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f42f7e65..eab8dfe4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2 + 1.2.47 Java Home myweb http://maven.apache.org @@ -18,13 +18,13 @@ com.oracle.bedrock bedrock-runtime-maven - 5.1.2 + 1.2.47 junit junit - 3.8.1 + 1.2.47 test @@ -53,7 +53,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 1.2.47 ${maven.compiler.source} ${maven.compiler.target} From 6385bd0ba812b0707f34b02ab55bd07b523979fc Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:45:22 +0530 Subject: [PATCH 08/54] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eab8dfe4..eabf3edd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.47 + 1.2 Java Home myweb http://maven.apache.org From cac7827b6ae60656c0bff0ab75c9f45535e677ba Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:26:53 +0530 Subject: [PATCH 09/54] Update pom.xml --- pom.xml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index eabf3edd..7e690346 100644 --- a/pom.xml +++ b/pom.xml @@ -4,27 +4,23 @@ in.RAHAM JAVA_APP war - 1.2 - Java Home myweb +1.2.6 Java Home myweb http://maven.apache.org kammana - 1.8 - 1.8 - - + com.oracle.bedrock bedrock-runtime-maven - 1.2.47 + 5.1.2 junit junit - 1.2.47 + 3.8.1 test @@ -42,9 +38,10 @@ - - central - https://repo.maven.apache.org/maven2 + + maven1 + Maven.org + http://repo1.maven.org/maven2 @@ -53,10 +50,10 @@ org.apache.maven.plugins maven-compiler-plugin - 1.2.47 + 3.8.1 - ${maven.compiler.source} - ${maven.compiler.target} + 1.8 + 1.8 From 1ef92c4679201a964ed6de4ba3a3030c69347c22 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 11:50:58 +0000 Subject: [PATCH 10/54] Update version to 1.2.19 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7e690346..13350a5e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war -1.2.6 Java Home myweb +1.2.19 Java Home myweb http://maven.apache.org @@ -14,13 +14,13 @@ com.oracle.bedrock bedrock-runtime-maven - 5.1.2 + 1.2.19 junit junit - 3.8.1 + 1.2.19 test @@ -50,7 +50,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 1.2.19 1.8 1.8 From a5f313a9c0f8934ac53bfcc0ebee848a0e392cbe Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:25:39 +0530 Subject: [PATCH 11/54] Update pom.xml --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 13350a5e..7e690346 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war -1.2.19 Java Home myweb +1.2.6 Java Home myweb http://maven.apache.org @@ -14,13 +14,13 @@ com.oracle.bedrock bedrock-runtime-maven - 1.2.19 + 5.1.2 junit junit - 1.2.19 + 3.8.1 test @@ -50,7 +50,7 @@ org.apache.maven.plugins maven-compiler-plugin - 1.2.19 + 3.8.1 1.8 1.8 From cf41f819594f6eccce2ff06a895ce07acd04203b Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:29:13 +0530 Subject: [PATCH 12/54] Update pom.xml --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7e690346..2d65c279 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,8 @@ in.RAHAM JAVA_APP war -1.2.6 Java Home myweb + 1.2.6 + Java Home myweb http://maven.apache.org From a9fc8323a3566bfdc4876d059d4fcbf81416b65e Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 12:00:06 +0000 Subject: [PATCH 13/54] Update version to 1.2.21 --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2d65c279..f95280b0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,8 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.6 - Java Home myweb +1.2.21 Java Home myweb http://maven.apache.org From 465e0e03064d98531de2a0f1f839fda1479c5746 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:31:17 +0530 Subject: [PATCH 14/54] Create Jenkinsfile --- Jenkinsfile | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..cacee13a --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,137 @@ +pipeline { + agent { + label 'docker' + } + tools { + maven 'maven' // Use the name configured in Jenkins + } + + stages { + stage('Checkout') { + steps { + script { + def gitInfo = checkout([$class: 'GitSCM', + branches: [[name: "*/${BRANCH_NAME}"]], + userRemoteConfigs: [[url: 'https://github.com/SaravanaNani/jenkins-java-project.git']] + ]) + def branchName = gitInfo.GIT_BRANCH.tokenize('/')[1] + echo "Branch name: ${branchName}" + } + } + } + + + stage('Package') { + steps { + sh ''' + cd /var/lib/jenkins/workspace/adq-java-app/ + mvn compile + mvn test + mvn package + ''' + } + } + stage('Rename and Upload WAR') { + steps { + script { + // Rename the WAR file + sh ''' + cd /var/lib/jenkins/workspace/adq-java-app/target/ + mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER}.war + ''' + + // Set the path of the artifact and upload path + def artifactPath = "/var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" + def uploadPath = "${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" + + // Upload to Google Cloud Storage using gsutil + sh """ + /google-cloud-sdk/bin/gsutil cp ${artifactPath} gs://adq-java-app/${uploadPath} + """ + } + } + } + + stage('Confirm and Get Private IP') { + steps { + script { + input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' + + def instanceName = "get-ubuntudesktop" + def projectId = "gcp-adq-pocproject-dev" + def zone = "us-central1-c" + + def instanceStatus = sh(script: "gcloud compute instances describe ${instanceName} --project=${projectId} --zone=${zone} --format='get(status)'", returnStdout: true).trim() + + if (instanceStatus != 'RUNNING') { + error "VM instance is not running. Deployment stopped." + } + + env.PRIVATE_IP = sh(script: ''' + gcloud compute instances list --filter="labels.adq-ubuntudesktop=env" --format="value(networkInterfaces[0].networkIP)" --limit=1 + ''', returnStdout: true).trim() + + echo "Private IP: ${env.PRIVATE_IP}" + } + } + } + + stage('Deploy and Restart Tomcat') { + steps { + script { + sh ''' + # Remove all .war files in the target directory + rm -f /var/lib/jenkins/workspace/adq-java-app/target/*.war + + # Get WAR from Artifactory + /google-cloud-sdk/bin/gsutil cp gs://adq-java-app/${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war /var/lib/jenkins/workspace/adq-java-app/target/ + ls -al /var/lib/jenkins/workspace/adq-java-app/target/ + + # Shutdown Tomcat + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-9.0.89/bin/shutdown.sh' + + # Remove old WAR files and directories + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-9.0.89/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-9.0.89/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" + + # Deploy the new WAR file + scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa /var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-9.0.89/webapps/ + + # Start Tomcat + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-9.0.89/bin/startup.sh' + ''' + } + } + } + + stage('Update pom.xml Version') { + steps { + script { + // Clone the repository + sh 'git clone https://github.com/SaravanaNani/jenkins-java-project.git' + + // Update the pom.xml with the new version + sh ''' + cd jenkins-java-project + git fetch --all + git checkout ${BRANCH_NAME} + perl -pi -e 's|^(\\s*.*\\s*)$|1.2.'${BUILD_NUMBER}'| if $. == 7' pom.xml + git config user.name "SaravanaNani" + git config user.email "saravana08052002@gmail.com" + git add pom.xml + git commit -m "Update version to 1.2.${BUILD_NUMBER}" + ''' + + // Push the changes using the stored credentials + withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_PAT')]) { + sh ''' + cd jenkins-java-project + git remote set-url origin https://$GITHUB_PAT@github.com/SaravanaNani/jenkins-java-project.git + git push origin ${BRANCH_NAME} + ''' + } + } + } + } + } +} From 8ee082ca96ac180d8f2ff24cc84b8db73b6894a9 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:37:14 +0530 Subject: [PATCH 15/54] Update pom.xml --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f95280b0..f46024ca 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,8 @@ in.RAHAM JAVA_APP war -1.2.21 Java Home myweb + 1.2.21 + Java Home myweb http://maven.apache.org From 96f79511ca508756059f8a7d9504371d3caf8dac Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 12:12:33 +0000 Subject: [PATCH 16/54] Update version to 1.2.25 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f46024ca..8d3d1ad1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.21 + 1.2.25 Java Home myweb http://maven.apache.org From fd825546f463fa99a679e283cd02a6ed4394c6ab Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 12:14:32 +0000 Subject: [PATCH 17/54] Update version to 1.2.26 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d3d1ad1..65805c0e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.25 + 1.2.26 Java Home myweb http://maven.apache.org From eded4e1f8afe12de81469bde346d52e84cbd9b7b Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Fri, 5 Jul 2024 17:44:45 +0530 Subject: [PATCH 18/54] Update Jenkinsfile --- Jenkinsfile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index cacee13a..35799d1b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -115,7 +115,16 @@ pipeline { cd jenkins-java-project git fetch --all git checkout ${BRANCH_NAME} - perl -pi -e 's|^(\\s*.*\\s*)$|1.2.'${BUILD_NUMBER}'| if $. == 7' pom.xml + # Debug before modification + echo "Before modification:" + sed -n '7p' pom.xml # Print line 7 before modification + + # Update line 7 with the new version + perl -i -pe 'if ($. == 7) { s|.*?|1.2.'${BUILD_NUMBER}'| }' pom.xml + + # Debug after modification + echo "After modification:" + sed -n '7p' pom.xml # Print line 7 after modification git config user.name "SaravanaNani" git config user.email "saravana08052002@gmail.com" git add pom.xml From 896c5290a710dc811941f6fb3d5f3bff4b770fe7 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Fri, 5 Jul 2024 12:20:30 +0000 Subject: [PATCH 19/54] Update version to 1.2.28 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 65805c0e..8250703c 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.26 + 1.2.28 Java Home myweb http://maven.apache.org From 77505243a67e303d3bc47d240dc786fdcd9d1e5e Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:09:47 +0530 Subject: [PATCH 20/54] Update Jenkinsfile --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 35799d1b..8a34c51d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { ''' } } - stage('Rename and Upload WAR') { + stage('Upload Artifact') { steps { script { // Rename the WAR file @@ -52,7 +52,7 @@ pipeline { } } - stage('Confirm and Get Private IP') { + stage('Confirmation') { steps { script { input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' @@ -76,7 +76,7 @@ pipeline { } } - stage('Deploy and Restart Tomcat') { + stage('Deployment') { steps { script { sh ''' From 58ab720f715d2cb956847b38bb2a660064f4a05c Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:12:37 +0530 Subject: [PATCH 21/54] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8a34c51d..f1defa07 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -68,7 +68,7 @@ pipeline { } env.PRIVATE_IP = sh(script: ''' - gcloud compute instances list --filter="labels.adq-ubuntudesktop=env" --format="value(networkInterfaces[0].networkIP)" --limit=1 + gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1 ''', returnStdout: true).trim() echo "Private IP: ${env.PRIVATE_IP}" From 7e51299ee44ba382eb67f4293c297098a20e6130 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 8 Jul 2024 10:16:28 +0530 Subject: [PATCH 22/54] Update Jenkinsfile --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f1defa07..ebcce7c1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -88,17 +88,17 @@ pipeline { ls -al /var/lib/jenkins/workspace/adq-java-app/target/ # Shutdown Tomcat - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-9.0.89/bin/shutdown.sh' + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/shutdown.sh' # Remove old WAR files and directories - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-9.0.89/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-9.0.89/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-10.1.25/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-10.1.25/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" # Deploy the new WAR file - scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa /var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-9.0.89/webapps/ + scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa /var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-10.1.25/webapps/ # Start Tomcat - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-9.0.89/bin/startup.sh' + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/startup.sh' ''' } } From 2a99474442d8cb22c8312813660335725575260f Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Mon, 8 Jul 2024 05:01:19 +0000 Subject: [PATCH 23/54] Update version to 1.2.32 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8250703c..892766ad 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.28 + 1.2.32 Java Home myweb http://maven.apache.org From 4040b896e7df3e000e67def703e04d0f1a42e5d0 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Mon, 8 Jul 2024 05:06:18 +0000 Subject: [PATCH 24/54] Update version to 1.2.34 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 892766ad..a50a516e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.32 + 1.2.34 Java Home myweb http://maven.apache.org From 25a4ed0b020590684b9c82b34556e82c20be3e86 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Mon, 8 Jul 2024 12:33:05 +0000 Subject: [PATCH 25/54] Update version to 1.2.36 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a50a516e..4ef1c25e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.34 + 1.2.36 Java Home myweb http://maven.apache.org From 5af3ad263e14b3b247de4a478f5e2143da2c35c5 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 8 Jul 2024 18:11:15 +0530 Subject: [PATCH 26/54] Update Jenkinsfile --- Jenkinsfile | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ebcce7c1..a95640c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,6 +5,13 @@ pipeline { tools { maven 'maven' // Use the name configured in Jenkins } + environment { + WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' + GCS_BUCKET = 'gs://adq-java-app' + PROJECT_ID = 'gcp-adq-pocproject-dev' + ZONE = 'us-central1-c' + INSTANCE_NAME = 'get-ubuntudesktop' + } stages { stage('Checkout') { @@ -20,33 +27,33 @@ pipeline { } } - stage('Package') { steps { sh ''' - cd /var/lib/jenkins/workspace/adq-java-app/ + cd ${WORKSPACE_DIR} mvn compile mvn test mvn package ''' } } + stage('Upload Artifact') { steps { script { // Rename the WAR file sh ''' - cd /var/lib/jenkins/workspace/adq-java-app/target/ + cd ${WORKSPACE_DIR}/target/ mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER}.war ''' // Set the path of the artifact and upload path - def artifactPath = "/var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" + def artifactPath = "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" def uploadPath = "${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" // Upload to Google Cloud Storage using gsutil sh """ - /google-cloud-sdk/bin/gsutil cp ${artifactPath} gs://adq-java-app/${uploadPath} + /google-cloud-sdk/bin/gsutil cp ${artifactPath} ${GCS_BUCKET}/${uploadPath} """ } } @@ -57,11 +64,7 @@ pipeline { script { input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' - def instanceName = "get-ubuntudesktop" - def projectId = "gcp-adq-pocproject-dev" - def zone = "us-central1-c" - - def instanceStatus = sh(script: "gcloud compute instances describe ${instanceName} --project=${projectId} --zone=${zone} --format='get(status)'", returnStdout: true).trim() + def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim() if (instanceStatus != 'RUNNING') { error "VM instance is not running. Deployment stopped." @@ -81,11 +84,11 @@ pipeline { script { sh ''' # Remove all .war files in the target directory - rm -f /var/lib/jenkins/workspace/adq-java-app/target/*.war + rm -f ${WORKSPACE_DIR}/target/*.war # Get WAR from Artifactory - /google-cloud-sdk/bin/gsutil cp gs://adq-java-app/${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war /var/lib/jenkins/workspace/adq-java-app/target/ - ls -al /var/lib/jenkins/workspace/adq-java-app/target/ + /google-cloud-sdk/bin/gsutil cp ${GCS_BUCKET}/${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${WORKSPACE_DIR}/target/ + ls -al ${WORKSPACE_DIR}/target/ # Shutdown Tomcat ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/shutdown.sh' @@ -95,7 +98,7 @@ pipeline { ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-10.1.25/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" # Deploy the new WAR file - scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa /var/lib/jenkins/workspace/adq-java-app/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-10.1.25/webapps/ + scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-10.1.25/webapps/ # Start Tomcat ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/startup.sh' From c45006e25b091ca1c14efb0f43dbc8c4fe6849a0 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:42:53 +0530 Subject: [PATCH 27/54] Update Jenkinsfile --- Jenkinsfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a95640c2..7b248a58 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -11,6 +11,7 @@ pipeline { PROJECT_ID = 'gcp-adq-pocproject-dev' ZONE = 'us-central1-c' INSTANCE_NAME = 'get-ubuntudesktop' + TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.25' } stages { @@ -91,17 +92,17 @@ pipeline { ls -al ${WORKSPACE_DIR}/target/ # Shutdown Tomcat - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/shutdown.sh' + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" # Remove old WAR files and directories - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-10.1.25/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find /root/apache-tomcat-10.1.25/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" # Deploy the new WAR file - scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:/root/apache-tomcat-10.1.25/webapps/ + scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ # Start Tomcat - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} '/root/apache-tomcat-10.1.25/bin/startup.sh' + ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" ''' } } From bde0b9c1aaf7242c7afb429a4e1113557f3629be Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Tue, 9 Jul 2024 05:13:55 +0000 Subject: [PATCH 28/54] Update version to 1.2.42 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ef1c25e..c5663c6e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.36 + 1.2.42 Java Home myweb http://maven.apache.org From ef77bb917a55a12b5f0e446dec24ed18098970ec Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Tue, 9 Jul 2024 10:48:50 +0530 Subject: [PATCH 29/54] Update Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7b248a58..ffbd187b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,6 @@ pipeline { stage('Package') { steps { sh ''' - cd ${WORKSPACE_DIR} mvn compile mvn test mvn package From 0fc72edfc90a33b1e8d8c7661815eaf72da700a5 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Tue, 9 Jul 2024 05:19:52 +0000 Subject: [PATCH 30/54] Update version to 1.2.43 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c5663c6e..8ca74191 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.42 + 1.2.43 Java Home myweb http://maven.apache.org From d225561dfaf43795900ab879bd16556f7591281d Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:30:29 +0530 Subject: [PATCH 31/54] Update pom.xml From ced67b4a0cb6bbcb6f9496421bca64b6f9410a24 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:34:26 +0530 Subject: [PATCH 32/54] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8ca74191..aaea743b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.43 + 1.2.2 Java Home myweb http://maven.apache.org From a6e93ae5048a0c321fbb744a67f92c9ccaf94740 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:24:04 +0530 Subject: [PATCH 33/54] Update pom.xml --- pom.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aaea743b..d6da721e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.2 + 1.2.99 Java Home myweb http://maven.apache.org @@ -57,6 +57,11 @@ 1.8 + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + From 4b6c5cea2f60b8344011c6b95a2d9d76309ffd14 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Thu, 11 Jul 2024 05:55:43 +0000 Subject: [PATCH 34/54] Update version to 1.2.104 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d6da721e..b36a2565 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.99 + 1.2.104 Java Home myweb http://maven.apache.org From e2a20c30e172be66e331c739a20c2674fb1d9d19 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 11 Jul 2024 11:45:00 +0530 Subject: [PATCH 35/54] Update Jenkinsfile --- Jenkinsfile | 59 +++++++++++++++++++---------------------------------- 1 file changed, 21 insertions(+), 38 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ffbd187b..567c5351 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,17 +3,18 @@ pipeline { label 'docker' } tools { - maven 'maven' // Use the name configured in Jenkins + maven 'maven' } environment { WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' - GCS_BUCKET = 'gs://adq-java-app' + GCS_BUCKET = 'gs://adq-java-app/' PROJECT_ID = 'gcp-adq-pocproject-dev' ZONE = 'us-central1-c' INSTANCE_NAME = 'get-ubuntudesktop' TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.25' + SONARQUBE_PROJECT_KEY = 'adq-java-app' + SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' } - stages { stage('Checkout') { steps { @@ -27,17 +28,27 @@ pipeline { } } } - + stage('SonarQube Analysis') { + steps { + withCredentials([string(credentialsId: 'sonar_token', variable: 'SONAR_TOKEN')]) { + sh ''' + mvn clean verify sonar:sonar \ + -Dsonar.projectKey=adq-java-app \ + -Dsonar.host.url=http://34.69.178.242:9000 \ + -Dsonar.login=${SONAR_TOKEN} + ''' + } + } + } stage('Package') { steps { sh ''' mvn compile mvn test mvn package - ''' + ''' } } - stage('Upload Artifact') { steps { script { @@ -58,83 +69,55 @@ pipeline { } } } - stage('Confirmation') { steps { script { input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' - def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim() - if (instanceStatus != 'RUNNING') { error "VM instance is not running. Deployment stopped." } - env.PRIVATE_IP = sh(script: ''' gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1 ''', returnStdout: true).trim() - echo "Private IP: ${env.PRIVATE_IP}" } } } - stage('Deployment') { steps { script { sh ''' - # Remove all .war files in the target directory rm -f ${WORKSPACE_DIR}/target/*.war - - # Get WAR from Artifactory /google-cloud-sdk/bin/gsutil cp ${GCS_BUCKET}/${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${WORKSPACE_DIR}/target/ ls -al ${WORKSPACE_DIR}/target/ - - # Shutdown Tomcat ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" - - # Remove old WAR files and directories ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" - - # Deploy the new WAR file scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ - - # Start Tomcat ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" ''' } } } - stage('Update pom.xml Version') { steps { script { - // Clone the repository sh 'git clone https://github.com/SaravanaNani/jenkins-java-project.git' - - // Update the pom.xml with the new version sh ''' cd jenkins-java-project git fetch --all git checkout ${BRANCH_NAME} - # Debug before modification echo "Before modification:" - sed -n '7p' pom.xml # Print line 7 before modification - - # Update line 7 with the new version + sed -n '7p' pom.xml perl -i -pe 'if ($. == 7) { s|.*?|1.2.'${BUILD_NUMBER}'| }' pom.xml - - # Debug after modification echo "After modification:" - sed -n '7p' pom.xml # Print line 7 after modification + sed -n '7p' pom.xml git config user.name "SaravanaNani" git config user.email "saravana08052002@gmail.com" git add pom.xml git commit -m "Update version to 1.2.${BUILD_NUMBER}" ''' - - // Push the changes using the stored credentials withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_PAT')]) { sh ''' cd jenkins-java-project @@ -144,6 +127,6 @@ pipeline { } } } - } - } + } + } } From 65cda9498093ec64e4ffaa08a8333cd42782527a Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Thu, 11 Jul 2024 06:23:32 +0000 Subject: [PATCH 36/54] Update version to 1.2.106 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b36a2565..e31a49c0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.104 + 1.2.106 Java Home myweb http://maven.apache.org From e8e518be3e370b4875c917d3b6ede0d3298524ef Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 08:47:33 +0000 Subject: [PATCH 37/54] Update version to 1.2.32 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e31a49c0..83af356a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.106 + 1.2.32 Java Home myweb http://maven.apache.org From 4fb60738709cd1e49d47a84c68db680ec16742af Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 08:51:24 +0000 Subject: [PATCH 38/54] Update version to 1.2.33 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 83af356a..bbbeea0a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.32 + 1.2.33 Java Home myweb http://maven.apache.org From edec52067a2169f6d9402f95bbc19b2e57f9330b Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 09:12:37 +0000 Subject: [PATCH 39/54] Update version to 1.2.37 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bbbeea0a..a2dac9b5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.33 + 1.2.37 Java Home myweb http://maven.apache.org From bcdc3b56eacf37724b3288fc90326c76426b3003 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 09:14:33 +0000 Subject: [PATCH 40/54] Update version to 1.2.38 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a2dac9b5..6319b205 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.37 + 1.2.38 Java Home myweb http://maven.apache.org From c5d2377b69fc7868fa36e8b2537a3d1ef6171f56 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 10:02:58 +0000 Subject: [PATCH 41/54] Update version to 1.2.49 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6319b205..219c0d01 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.38 + 1.2.49 Java Home myweb http://maven.apache.org From 05098fd9e4c623c3159f8cb4058514c8a0789aad Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 10:15:41 +0000 Subject: [PATCH 42/54] Update version to 1.2.51 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 219c0d01..236dcc64 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.49 + 1.2.51 Java Home myweb http://maven.apache.org From 9f5c45d78967d6b40e789bdf70622c7b721a907f Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 10:23:16 +0000 Subject: [PATCH 43/54] Update version to 1.2.53 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 236dcc64..ed379a2f 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.51 + 1.2.53 Java Home myweb http://maven.apache.org From 55e02e9368dfa4a1105d87eda1849fe5dab9d884 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:55:01 +0530 Subject: [PATCH 44/54] Create Jenkinsfile-1 --- Jenkinsfile-1 | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 Jenkinsfile-1 diff --git a/Jenkinsfile-1 b/Jenkinsfile-1 new file mode 100644 index 00000000..e4bf76d0 --- /dev/null +++ b/Jenkinsfile-1 @@ -0,0 +1,144 @@ +pipeline { + agent { + label 'docker' + } + tools { + maven 'maven' + } + environment { + WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' + GCS_BUCKET = 'gs://adq-java-app/' + PROJECT_ID = 'gcp-adq-pocproject-dev' + ZONE = 'us-central1-c' + INSTANCE_NAME = 'get-ubuntudesktop' + TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.26' + SONARQUBE_PROJECT_KEY = 'adq-java-app' + SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' + NEXUS_URL = '34.69.178.242:8081' + NEXUS_REPOSITORY = 'adq-java-app' + NEXUS_GROUP_ID = 'in.RAHAM' + NEXUS_ARTIFACT_ID = 'JAVA_APP' + NEXUS_VERSION = 'nexus3' + NEXUS_PROTOCOL = 'http' + SSH_KEY_PATH = '/var/lib/jenkins/.ssh/id_rsa' + } + stages { + stage('Checkout') { + steps { + script { + def gitInfo = checkout([$class: 'GitSCM', + branches: [[name: "*/${BRANCH_NAME}"]], + userRemoteConfigs: [[url: 'https://github.com/SaravanaNani/jenkins-java-project.git']] + ]) + def branchName = gitInfo.GIT_BRANCH.tokenize('/')[1] + echo "Branch name: ${branchName}" + } + } + } + stage('SonarQube Analysis') { + steps { + withCredentials([string(credentialsId: 'sonar_token', variable: 'SONAR_TOKEN')]) { + sh ''' + mvn clean verify sonar:sonar \ + -Dsonar.projectKey=${SONARQUBE_PROJECT_KEY} \ + -Dsonar.host.url=${SONARQUBE_HOST_URL} \ + -Dsonar.login=${SONAR_TOKEN} + ''' + } + } + } + + stage('Package') { + steps { + sh ''' + mvn compile + mvn test + mvn package + ''' + } + } + stage('Upload Artifact to Nexus') { + steps { + script { + sh ''' + cd ${WORKSPACE_DIR}/target/ + mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER} + ''' + nexusArtifactUploader artifacts: [[artifactId: "${NEXUS_ARTIFACT_ID}", classifier: '', file: "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}", type: 'war']], credentialsId: 'nexus_id', groupId: "${NEXUS_GROUP_ID}", nexusUrl: "${NEXUS_URL}", nexusVersion: "${NEXUS_VERSION}", protocol: "${NEXUS_PROTOCOL}", repository: "${NEXUS_REPOSITORY}", version: "1.2.${BUILD_NUMBER}" + } + } + } + stage('Confirmation') { + steps { + script { + input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' + def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim() + if (instanceStatus != 'RUNNING') { + error "VM instance is not running. Deployment stopped." + } + env.PRIVATE_IP = sh(script: ''' + gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1 + ''', returnStdout: true).trim() + echo "Private IP: ${env.PRIVATE_IP}" + } + } + } + stage('Download and Deploy Artifact') { + steps { + script { + // Use Jenkins credentials to authenticate with Nexus + withCredentials([usernamePassword(credentialsId: 'nexus_id', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { + sh ''' + # Clear the target directory + ls -al ${WORKSPACE_DIR}/target/ + rm -r ${WORKSPACE_DIR}/target/* + ls -al ${WORKSPACE_DIR}/target/ + + # Download the artifact from Nexus + wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/RAHAM/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war + + # List the target directory to confirm the file is downloaded + ls -al ${WORKSPACE_DIR}/target/ + + # Deployment steps + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" + scp -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" + ''' + } + } + } + } + + stage('Update pom.xml Version') { + steps { + script { + sh 'git clone https://github.com/SaravanaNani/jenkins-java-project.git' + sh ''' + cd jenkins-java-project + git fetch --all + git checkout ${BRANCH_NAME} + echo "Before modification:" + sed -n '7p' pom.xml + perl -i -pe 'if ($. == 7) { s|.*?|1.2.'${BUILD_NUMBER}'| }' pom.xml + echo "After modification:" + sed -n '7p' pom.xml + git config user.name "SaravanaNani" + git config user.email "saravana08052002@gmail.com" + git add pom.xml + git commit -m "Update version to 1.2.${BUILD_NUMBER}" + ''' + withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_PAT')]) { + sh ''' + cd jenkins-java-project + git remote set-url origin https://$GITHUB_PAT@github.com/SaravanaNani/jenkins-java-project.git + git push origin ${BRANCH_NAME} + ''' + } + } + } + } + } +} From a0c17ca708803c1eaf79ff378c3dd362d7f10026 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Sat, 13 Jul 2024 10:26:37 +0000 Subject: [PATCH 45/54] Update version to 1.2.109 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ed379a2f..4b51f591 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.RAHAM JAVA_APP war - 1.2.53 + 1.2.109 Java Home myweb http://maven.apache.org From 38813cde0bd434e6029bd0ecf23ec5865a6d8457 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Sat, 13 Jul 2024 15:57:35 +0530 Subject: [PATCH 46/54] Update Jenkinsfile-1 --- Jenkinsfile-1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile-1 b/Jenkinsfile-1 index e4bf76d0..41d273b8 100644 --- a/Jenkinsfile-1 +++ b/Jenkinsfile-1 @@ -7,7 +7,6 @@ pipeline { } environment { WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' - GCS_BUCKET = 'gs://adq-java-app/' PROJECT_ID = 'gcp-adq-pocproject-dev' ZONE = 'us-central1-c' INSTANCE_NAME = 'get-ubuntudesktop' From 49ac5cf01034acf47fcc0fe91a734dbccca2d6a8 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:00:16 +0530 Subject: [PATCH 47/54] Update Jenkinsfile --- Jenkinsfile | 67 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 28 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 567c5351..a1de8c3f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,19 +1,25 @@ pipeline { agent { - label 'docker' + label 'docker' } tools { maven 'maven' } environment { WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' - GCS_BUCKET = 'gs://adq-java-app/' PROJECT_ID = 'gcp-adq-pocproject-dev' ZONE = 'us-central1-c' INSTANCE_NAME = 'get-ubuntudesktop' - TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.25' + TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.26' SONARQUBE_PROJECT_KEY = 'adq-java-app' SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' + NEXUS_URL = '34.69.178.242:8081' + NEXUS_REPOSITORY = 'adq-java-app' + NEXUS_GROUP_ID = 'in.RAHAM' + NEXUS_ARTIFACT_ID = 'JAVA_APP' + NEXUS_VERSION = 'nexus3' + NEXUS_PROTOCOL = 'http' + SSH_KEY_PATH = '/var/lib/jenkins/.ssh/id_rsa' } stages { stage('Checkout') { @@ -33,13 +39,14 @@ pipeline { withCredentials([string(credentialsId: 'sonar_token', variable: 'SONAR_TOKEN')]) { sh ''' mvn clean verify sonar:sonar \ - -Dsonar.projectKey=adq-java-app \ - -Dsonar.host.url=http://34.69.178.242:9000 \ + -Dsonar.projectKey=${SONARQUBE_PROJECT_KEY} \ + -Dsonar.host.url=${SONARQUBE_HOST_URL} \ -Dsonar.login=${SONAR_TOKEN} ''' } } } + stage('Package') { steps { sh ''' @@ -49,24 +56,15 @@ pipeline { ''' } } - stage('Upload Artifact') { + stage('Upload Artifact to Nexus') { steps { script { - // Rename the WAR file sh ''' cd ${WORKSPACE_DIR}/target/ - mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER}.war + mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER} ''' - - // Set the path of the artifact and upload path - def artifactPath = "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" - def uploadPath = "${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war" - - // Upload to Google Cloud Storage using gsutil - sh """ - /google-cloud-sdk/bin/gsutil cp ${artifactPath} ${GCS_BUCKET}/${uploadPath} - """ - } + nexusArtifactUploader artifacts: [[artifactId: "${NEXUS_ARTIFACT_ID}", classifier: '', file: "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}", type: 'war']], credentialsId: 'nexus_id', groupId: "${NEXUS_GROUP_ID}", nexusUrl: "${NEXUS_URL}", nexusVersion: "${NEXUS_VERSION}", protocol: "${NEXUS_PROTOCOL}", repository: "${NEXUS_REPOSITORY}", version: "1.2.${BUILD_NUMBER}" + } } } stage('Confirmation') { @@ -87,19 +85,32 @@ pipeline { stage('Deployment') { steps { script { - sh ''' - rm -f ${WORKSPACE_DIR}/target/*.war - /google-cloud-sdk/bin/gsutil cp ${GCS_BUCKET}/${BRANCH_NAME}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${WORKSPACE_DIR}/target/ - ls -al ${WORKSPACE_DIR}/target/ - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" - scp -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ - ssh -o StrictHostKeyChecking=no -i /var/lib/jenkins/.ssh/id_rsa root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" - ''' + // Use Jenkins credentials to authenticate with Nexus + withCredentials([usernamePassword(credentialsId: 'nexus_id', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { + sh ''' + # Clear the target directory + ls -al ${WORKSPACE_DIR}/target/ + rm -r ${WORKSPACE_DIR}/target/* + ls -al ${WORKSPACE_DIR}/target/ + + # Download the artifact from Nexus + wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/RAHAM/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war + + # List the target directory to confirm the file is downloaded + ls -al ${WORKSPACE_DIR}/target/ + + # Deployment steps + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" + scp -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ + ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" + ''' + } } } } + stage('Update pom.xml Version') { steps { script { From 9196c2c48e36ab5f03f0ea4680d3ad8a4dc6e508 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Sat, 13 Jul 2024 16:14:51 +0530 Subject: [PATCH 48/54] Delete Jenkinsfile-1 --- Jenkinsfile-1 | 143 -------------------------------------------------- 1 file changed, 143 deletions(-) delete mode 100644 Jenkinsfile-1 diff --git a/Jenkinsfile-1 b/Jenkinsfile-1 deleted file mode 100644 index 41d273b8..00000000 --- a/Jenkinsfile-1 +++ /dev/null @@ -1,143 +0,0 @@ -pipeline { - agent { - label 'docker' - } - tools { - maven 'maven' - } - environment { - WORKSPACE_DIR = '/var/lib/jenkins/workspace/adq-java-app' - PROJECT_ID = 'gcp-adq-pocproject-dev' - ZONE = 'us-central1-c' - INSTANCE_NAME = 'get-ubuntudesktop' - TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.26' - SONARQUBE_PROJECT_KEY = 'adq-java-app' - SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' - NEXUS_URL = '34.69.178.242:8081' - NEXUS_REPOSITORY = 'adq-java-app' - NEXUS_GROUP_ID = 'in.RAHAM' - NEXUS_ARTIFACT_ID = 'JAVA_APP' - NEXUS_VERSION = 'nexus3' - NEXUS_PROTOCOL = 'http' - SSH_KEY_PATH = '/var/lib/jenkins/.ssh/id_rsa' - } - stages { - stage('Checkout') { - steps { - script { - def gitInfo = checkout([$class: 'GitSCM', - branches: [[name: "*/${BRANCH_NAME}"]], - userRemoteConfigs: [[url: 'https://github.com/SaravanaNani/jenkins-java-project.git']] - ]) - def branchName = gitInfo.GIT_BRANCH.tokenize('/')[1] - echo "Branch name: ${branchName}" - } - } - } - stage('SonarQube Analysis') { - steps { - withCredentials([string(credentialsId: 'sonar_token', variable: 'SONAR_TOKEN')]) { - sh ''' - mvn clean verify sonar:sonar \ - -Dsonar.projectKey=${SONARQUBE_PROJECT_KEY} \ - -Dsonar.host.url=${SONARQUBE_HOST_URL} \ - -Dsonar.login=${SONAR_TOKEN} - ''' - } - } - } - - stage('Package') { - steps { - sh ''' - mvn compile - mvn test - mvn package - ''' - } - } - stage('Upload Artifact to Nexus') { - steps { - script { - sh ''' - cd ${WORKSPACE_DIR}/target/ - mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER} - ''' - nexusArtifactUploader artifacts: [[artifactId: "${NEXUS_ARTIFACT_ID}", classifier: '', file: "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}", type: 'war']], credentialsId: 'nexus_id', groupId: "${NEXUS_GROUP_ID}", nexusUrl: "${NEXUS_URL}", nexusVersion: "${NEXUS_VERSION}", protocol: "${NEXUS_PROTOCOL}", repository: "${NEXUS_REPOSITORY}", version: "1.2.${BUILD_NUMBER}" - } - } - } - stage('Confirmation') { - steps { - script { - input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' - def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim() - if (instanceStatus != 'RUNNING') { - error "VM instance is not running. Deployment stopped." - } - env.PRIVATE_IP = sh(script: ''' - gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1 - ''', returnStdout: true).trim() - echo "Private IP: ${env.PRIVATE_IP}" - } - } - } - stage('Download and Deploy Artifact') { - steps { - script { - // Use Jenkins credentials to authenticate with Nexus - withCredentials([usernamePassword(credentialsId: 'nexus_id', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { - sh ''' - # Clear the target directory - ls -al ${WORKSPACE_DIR}/target/ - rm -r ${WORKSPACE_DIR}/target/* - ls -al ${WORKSPACE_DIR}/target/ - - # Download the artifact from Nexus - wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/RAHAM/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war - - # List the target directory to confirm the file is downloaded - ls -al ${WORKSPACE_DIR}/target/ - - # Deployment steps - ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/shutdown.sh" - ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type d -name 'JAVA_APP-1.2.*' -exec rm -rf {} +" - ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "find ${TARGET_HOST_PATH}/webapps/ -type f -name 'JAVA_APP-1.2*.war' -exec rm -f {} +" - scp -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war root@${PRIVATE_IP}:${TARGET_HOST_PATH}/webapps/ - ssh -o StrictHostKeyChecking=no -i ${SSH_KEY_PATH} root@${PRIVATE_IP} "${TARGET_HOST_PATH}/bin/startup.sh" - ''' - } - } - } - } - - stage('Update pom.xml Version') { - steps { - script { - sh 'git clone https://github.com/SaravanaNani/jenkins-java-project.git' - sh ''' - cd jenkins-java-project - git fetch --all - git checkout ${BRANCH_NAME} - echo "Before modification:" - sed -n '7p' pom.xml - perl -i -pe 'if ($. == 7) { s|.*?|1.2.'${BUILD_NUMBER}'| }' pom.xml - echo "After modification:" - sed -n '7p' pom.xml - git config user.name "SaravanaNani" - git config user.email "saravana08052002@gmail.com" - git add pom.xml - git commit -m "Update version to 1.2.${BUILD_NUMBER}" - ''' - withCredentials([string(credentialsId: 'github-pat', variable: 'GITHUB_PAT')]) { - sh ''' - cd jenkins-java-project - git remote set-url origin https://$GITHUB_PAT@github.com/SaravanaNani/jenkins-java-project.git - git push origin ${BRANCH_NAME} - ''' - } - } - } - } - } -} From 4088f5c815b8ad9554263db4fceb02a14cf7c8d6 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:40:07 +0530 Subject: [PATCH 49/54] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b51f591..29fe4976 100644 --- a/pom.xml +++ b/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - in.RAHAM + in.ADQ-JAVA-APP JAVA_APP war 1.2.109 From 1142b1ddbf5cefc269c4bf70bcfa5a595aa0e692 Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Mon, 15 Jul 2024 10:42:10 +0530 Subject: [PATCH 50/54] Update Jenkinsfile --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a1de8c3f..6a952219 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' NEXUS_URL = '34.69.178.242:8081' NEXUS_REPOSITORY = 'adq-java-app' - NEXUS_GROUP_ID = 'in.RAHAM' + NEXUS_GROUP_ID = 'in.ADQ-JAVA-APP' NEXUS_ARTIFACT_ID = 'JAVA_APP' NEXUS_VERSION = 'nexus3' NEXUS_PROTOCOL = 'http' @@ -94,7 +94,7 @@ pipeline { ls -al ${WORKSPACE_DIR}/target/ # Download the artifact from Nexus - wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/RAHAM/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war + wget --user=${NEXUS_USER} --password=${NEXUS_PASSWORD} -O ${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}.war ${NEXUS_PROTOCOL}://${NEXUS_URL}/repository/${NEXUS_REPOSITORY}/in/ADQ-JAVA-APP/JAVA_APP/1.2.${BUILD_NUMBER}/JAVA_APP-1.2.${BUILD_NUMBER}.war # List the target directory to confirm the file is downloaded ls -al ${WORKSPACE_DIR}/target/ From 682881e4affdfe24d60fcd581a80d3883654d69c Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Mon, 15 Jul 2024 05:26:38 +0000 Subject: [PATCH 51/54] Update version to 1.2.113 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29fe4976..ba18960d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.ADQ-JAVA-APP JAVA_APP war - 1.2.109 + 1.2.113 Java Home myweb http://maven.apache.org From 925d4803f45a5448f2b8fe7f8e5c09e773d7ff62 Mon Sep 17 00:00:00 2001 From: SaravanaNani Date: Thu, 25 Jul 2024 09:50:57 +0000 Subject: [PATCH 52/54] Update version to 1.2.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ba18960d..739d7060 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ in.ADQ-JAVA-APP JAVA_APP war - 1.2.113 + 1.2.2 Java Home myweb http://maven.apache.org From 8f7427158bcc1036b1da3a06ce5df8845c58fc6b Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:26:17 +0530 Subject: [PATCH 53/54] Update Jenkinsfile --- Jenkinsfile | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6a952219..bf78d1e7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,6 +20,7 @@ pipeline { NEXUS_VERSION = 'nexus3' NEXUS_PROTOCOL = 'http' SSH_KEY_PATH = '/var/lib/jenkins/.ssh/id_rsa' + ADMIN_EMAIL = 'getadqdevops@gmail.com' } stages { stage('Checkout') { @@ -64,13 +65,12 @@ pipeline { mv JAVA_APP-1.2.*.war JAVA_APP-1.2.${BUILD_NUMBER} ''' nexusArtifactUploader artifacts: [[artifactId: "${NEXUS_ARTIFACT_ID}", classifier: '', file: "${WORKSPACE_DIR}/target/JAVA_APP-1.2.${BUILD_NUMBER}", type: 'war']], credentialsId: 'nexus_id', groupId: "${NEXUS_GROUP_ID}", nexusUrl: "${NEXUS_URL}", nexusVersion: "${NEXUS_VERSION}", protocol: "${NEXUS_PROTOCOL}", repository: "${NEXUS_REPOSITORY}", version: "1.2.${BUILD_NUMBER}" - } + } } } - stage('Confirmation') { + stage('Check Infrastructure and Request Approval') { steps { script { - input message: 'Are you sure you want to proceed with the deployment?', ok: 'Yes' def instanceStatus = sh(script: "gcloud compute instances describe ${INSTANCE_NAME} --project=${PROJECT_ID} --zone=${ZONE} --format='get(status)'", returnStdout: true).trim() if (instanceStatus != 'RUNNING') { error "VM instance is not running. Deployment stopped." @@ -79,13 +79,44 @@ pipeline { gcloud compute instances list --filter="labels.adq_ubuntudesktop=app" --format="value(networkInterfaces[0].networkIP)" --limit=1 ''', returnStdout: true).trim() echo "Private IP: ${env.PRIVATE_IP}" + + emailext ( + subject: "Approval Needed: Proceed with Deployment", + body: """ +

The infrastructure is ready for deployment.

+

Instance Status: ${instanceStatus}

+

Private IP: ${env.PRIVATE_IP}

+

Please approve the execution of the deployment stage.

+

Click here to provide approval.

+ """, + mimeType: 'text/html', + to: "${env.ADMIN_EMAIL}" + ) + echo 'Approval email sent. Awaiting manual approval...' + + def userInput = input( + id: 'userInput', message: 'Approval needed to proceed with the deployment.', parameters: [ + [$class: 'BooleanParameterDefinition', defaultValue: true, description: 'Approve to proceed?', name: 'Proceed'] + ] + ) + + if (!userInput) { + echo 'Aborted by user.' + currentBuild.result = 'ABORTED' + emailext ( + subject: "Approval Denied: Deployment", + body: "The stage to deploy has been denied and will not be executed.", + mimeType: 'text/html', + to: "${env.ADMIN_EMAIL}" + ) + error('User aborted the stage.') + } } } } stage('Deployment') { steps { script { - // Use Jenkins credentials to authenticate with Nexus withCredentials([usernamePassword(credentialsId: 'nexus_id', usernameVariable: 'NEXUS_USER', passwordVariable: 'NEXUS_PASSWORD')]) { sh ''' # Clear the target directory From bbc9dd9d558d0217d136c94a2bb17984b123381e Mon Sep 17 00:00:00 2001 From: Saravana <67310667+SaravanaNani@users.noreply.github.com> Date: Thu, 8 Aug 2024 11:33:03 +0530 Subject: [PATCH 54/54] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index bf78d1e7..75ac6b94 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,7 +10,7 @@ pipeline { PROJECT_ID = 'gcp-adq-pocproject-dev' ZONE = 'us-central1-c' INSTANCE_NAME = 'get-ubuntudesktop' - TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.26' + TARGET_HOST_PATH = '/opt/tomcat/apache-tomcat-10.1.28' SONARQUBE_PROJECT_KEY = 'adq-java-app' SONARQUBE_HOST_URL = 'http://34.69.178.242:9000' NEXUS_URL = '34.69.178.242:8081'