From f562d49ecbf25938ad1d05218d1b854cf17012e5 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 11:09:19 +0530 Subject: [PATCH 01/60] First sample --- Jenkinsfile | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++ deploy.sh | 46 +++++++++++++++++++++++++++ pom.xml | 44 ++++++++++++++++++++++++++ 3 files changed, 181 insertions(+) create mode 100644 Jenkinsfile create mode 100644 deploy.sh create mode 100644 pom.xml diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8326d46 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,91 @@ +pipeline { + agent any + + triggers { + githubPush() // auto-triggers when code is pushed/merged + } + + environment { + // Where params file will be saved on Jenkins VM + PARAMS_FILE = "/tmp/jenkins-params/${env.JOB_NAME}-build-params.env" + } + + stages { + + stage('1. Extract Parameters from Merge') { + steps { + script { + // Get branch name (strip "origin/" prefix) + env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' + // Get full commit hash + env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + // Who triggered this build + env.BUILD_CAUSE = 'jenkins-bot' + // For this learning exercise, always do a Build + env.REQUIRED = 'Build' + env.BUILD_ENV = 'uat' + + echo """ + ======= Parameters Extracted ======= + BRANCH : ${env.BRANCH} + COMMIT_HASH : ${env.COMMIT_HASH} + BUILD_CAUSE : ${env.BUILD_CAUSE} + REQUIRED : ${env.REQUIRED} + BUILD_ENV : ${env.BUILD_ENV} + ==================================== + """ + } + } + } + + stage('2. Write Params to File') { + steps { + script { + // Create the directory if it doesn't exist + sh "mkdir -p \$(dirname ${env.PARAMS_FILE})" + + // Write all params — shell script will read this + writeFile file: env.PARAMS_FILE, text: """\ +JOB_NAME=${env.JOB_NAME} +BRANCH=${env.BRANCH} +COMMIT_HASH=${env.COMMIT_HASH} +BUILD_ENV=${env.BUILD_ENV} +REQUIRED=${env.REQUIRED} +BUILD_CAUSE=${env.BUILD_CAUSE} +WORKSPACE=${env.WORKSPACE} +""" + echo "✅ Params written to: ${env.PARAMS_FILE}" + sh "cat ${env.PARAMS_FILE}" + } + } + } + + stage('3. Build WAR') { + steps { + script { + sh """ + echo "📦 Reading params and building WAR..." + bash ${env.WORKSPACE}/java_deployment.sh ${env.PARAMS_FILE} + """ + } + } + } + + stage('4. Archive WAR') { + steps { + // Save the WAR as a Jenkins build artifact + archiveArtifacts artifacts: 'target/*.war', fingerprint: true + echo "✅ WAR archived successfully" + } + } + } + + post { + success { + echo "🎉 Build SUCCESS — Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" + } + failure { + echo "❌ Build FAILED — Check console output above" + } + } +} \ No newline at end of file diff --git a/deploy.sh b/deploy.sh new file mode 100644 index 0000000..329dea2 --- /dev/null +++ b/deploy.sh @@ -0,0 +1,46 @@ +#!/bin/bash +# java_deployment.sh +# Reads params from file and builds the WAR + +set -e +trap 'echo "❌ Failed at line $LINENO"' ERR + +# ── Step 1: Read the params file ────────────────────────── +PARAMS_FILE=$1 + +if [[ -z "$PARAMS_FILE" || ! -f "$PARAMS_FILE" ]]; then + echo "❌ ERROR: Params file not found: $PARAMS_FILE" + exit 1 +fi + +echo "📄 Reading params from: $PARAMS_FILE" +set -a # auto-export all variables +source "$PARAMS_FILE" +set +a + +# ── Step 2: Print what we got ───────────────────────────── +echo "===============================" +echo "JOB_NAME : $JOB_NAME" +echo "BRANCH : $BRANCH" +echo "COMMIT_HASH : $COMMIT_HASH" +echo "BUILD_ENV : $BUILD_ENV" +echo "REQUIRED : $REQUIRED" +echo "WORKSPACE : $WORKSPACE" +echo "===============================" + +# ── Step 3: Go to workspace and build WAR ───────────────── +cd "$WORKSPACE" + +echo "🔨 Starting Maven WAR build..." +mvn clean package -DskipTests + +# ── Step 4: Confirm WAR was created ─────────────────────── +WAR_FILE="$WORKSPACE/target/SampleWebApp.war" + +if [[ -f "$WAR_FILE" ]]; then + echo "✅ WAR built successfully: $WAR_FILE" + ls -lh "$WAR_FILE" +else + echo "❌ WAR file not found after build!" + exit 1 +fi \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..17e2212 --- /dev/null +++ b/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + com.sample + SampleWebApp + war + 1.0 + SampleWebApp + + + web + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + web + SampleWebApp + + false + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 11 + 11 + + + + + SampleWebApp + + + From 5f92ba977f49ee58519624b50fbf122f3dbd61d9 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 11:39:57 +0530 Subject: [PATCH 02/60] First Sample-PollSCM --- Jenkinsfile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8326d46..1a402f8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,11 @@ pipeline { agent any + + triggers { + pollSCM('H/5 * * * *') + } + triggers { githubPush() // auto-triggers when code is pushed/merged } @@ -65,7 +70,7 @@ WORKSPACE=${env.WORKSPACE} script { sh """ echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/java_deployment.sh ${env.PARAMS_FILE} + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} """ } } From 3d7c2474977f23111f476666d95bc5fcd71e3f6f Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 11:50:15 +0530 Subject: [PATCH 03/60] First Sample-PollSCM1 --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1a402f8..23d50ff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,9 +6,9 @@ pipeline { pollSCM('H/5 * * * *') } - triggers { - githubPush() // auto-triggers when code is pushed/merged - } + // triggers { + // githubPush() // auto-triggers when code is pushed/merged + // } environment { // Where params file will be saved on Jenkins VM From 2b754efaf7b64cf85f8727855d5a372a42d07305 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 12:16:10 +0530 Subject: [PATCH 04/60] First Sample-WAR copy --- Jenkinsfile | 2 +- deploy.sh | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 23d50ff..3484060 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,7 +3,7 @@ pipeline { triggers { - pollSCM('H/5 * * * *') + pollSCM('* * * * *') } // triggers { diff --git a/deploy.sh b/deploy.sh index 329dea2..030e79f 100644 --- a/deploy.sh +++ b/deploy.sh @@ -43,4 +43,14 @@ if [[ -f "$WAR_FILE" ]]; then else echo "❌ WAR file not found after build!" exit 1 -fi \ No newline at end of file +fi + +DEPLOY_DIR= "/home/praveen/app_scripts" +cp "$WAR_FILE" "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" + +if [[-f "$DEPLOY_DIR/SampleWebApp-${COMMIT_HASH:0:7}.war"]]: then + echo "✅ WAR copied successfully!" +else + echo "❌ WAR copy failed" + exit 1 +fi From a64b69780379b94de26ab99a93f6ee19c589dcd9 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 13:03:40 +0530 Subject: [PATCH 05/60] First Sample-WAR copy1 --- deploy.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 030e79f..f45d1c8 100644 --- a/deploy.sh +++ b/deploy.sh @@ -45,10 +45,10 @@ else exit 1 fi -DEPLOY_DIR= "/home/praveen/app_scripts" +DEPLOY_DIR="/home/praveen/app_scripts/" cp "$WAR_FILE" "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" -if [[-f "$DEPLOY_DIR/SampleWebApp-${COMMIT_HASH:0:7}.war"]]: then +if [[ -f "$DEPLOY_DIR/SampleWebApp-${COMMIT_HASH:0:7}.war" ]]; then echo "✅ WAR copied successfully!" else echo "❌ WAR copy failed" From dab049c4af2dbfdb8c51e3ed3c498473978020c6 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 13:11:54 +0530 Subject: [PATCH 06/60] First Sample-WAR copy2 --- deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index f45d1c8..2fd47e5 100644 --- a/deploy.sh +++ b/deploy.sh @@ -48,7 +48,7 @@ fi DEPLOY_DIR="/home/praveen/app_scripts/" cp "$WAR_FILE" "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" -if [[ -f "$DEPLOY_DIR/SampleWebApp-${COMMIT_HASH:0:7}.war" ]]; then +if [[ -f "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" ]]; then echo "✅ WAR copied successfully!" else echo "❌ WAR copy failed" From dab878f426f94849dcb970aeedb4f9d19dae2dbf Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 19:02:39 +0530 Subject: [PATCH 07/60] New trial --- Jenkinsfile | 12 ++++++------ deploy.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3484060..92cd2c2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,14 +2,14 @@ pipeline { agent any - triggers { - pollSCM('* * * * *') - } - // triggers { - // githubPush() // auto-triggers when code is pushed/merged + // pollSCM('* * * * *') // } + triggers { + githubPush() // auto-triggers when code is pushed/merged + } + environment { // Where params file will be saved on Jenkins VM PARAMS_FILE = "/tmp/jenkins-params/${env.JOB_NAME}-build-params.env" @@ -21,7 +21,7 @@ pipeline { steps { script { // Get branch name (strip "origin/" prefix) - env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' + env.BRANCH = sh(script: 'git rev-parse, --abbrev-ref HEAD', returnStdout: true).trim() // Get full commit hash env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() // Who triggered this build diff --git a/deploy.sh b/deploy.sh index 2fd47e5..bc7f758 100644 --- a/deploy.sh +++ b/deploy.sh @@ -54,3 +54,44 @@ else echo "❌ WAR copy failed" exit 1 fi + +# # ── Step 6: Deploy to Tomcat ────────────────────────────── +# TOMCAT_WEBAPPS="/var/lib/tomcat9/webapps" +# APP_NAME="SampleWebApp" + +# echo "🚀 Starting Tomcat deployment..." + +# # Stop Tomcat +# echo "⏹ Stopping Tomcat..." +# sudo systemctl stop tomcat9 + +# # Remove old deployment +# if [[ -d "$TOMCAT_WEBAPPS/$APP_NAME" ]]; then +# echo "🗑 Removing old deployment..." +# sudo rm -rf "$TOMCAT_WEBAPPS/$APP_NAME" +# fi + +# if [[ -f "$TOMCAT_WEBAPPS/$APP_NAME.war" ]]; then +# echo "🗑 Removing old WAR..." +# sudo rm -f "$TOMCAT_WEBAPPS/$APP_NAME.war" +# fi + +# # Copy new WAR to Tomcat +# echo "📂 Copying new WAR to Tomcat..." +# sudo cp "$WAR_FILE" "$TOMCAT_WEBAPPS/$APP_NAME.war" + +# # Start Tomcat +# echo "▶ Starting Tomcat..." +# sudo systemctl start tomcat9 + +# # ── Step 7: Verify Deployment ───────────────────────────── +# echo "⏳ Waiting for Tomcat to deploy WAR..." +# sleep 15 + +# if [[ -d "$TOMCAT_WEBAPPS/$APP_NAME" ]]; then +# echo "✅ Deployment successful!" +# echo "🌐 App available at: http://localhost:8080/$APP_NAME" +# else +# echo "❌ Deployment failed — folder not created by Tomcat" +# exit 1 +# fi \ No newline at end of file From b9201b6fcd9f8bbfbfa57e8c0d92a575ed5af1c9 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 19:04:07 +0530 Subject: [PATCH 08/60] New trial1 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 92cd2c2..6fa555d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { script { // Get branch name (strip "origin/" prefix) - env.BRANCH = sh(script: 'git rev-parse, --abbrev-ref HEAD', returnStdout: true).trim() + env.BRANCH = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() // Get full commit hash env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() // Who triggered this build From a4699d85e127b48bf2998aef6776ea227711447a Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 9 Apr 2026 19:08:18 +0530 Subject: [PATCH 09/60] New trial2 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6fa555d..919a205 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { steps { script { // Get branch name (strip "origin/" prefix) - env.BRANCH = sh(script: 'git rev-parse --abbrev-ref HEAD', returnStdout: true).trim() + env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' // Get full commit hash env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() // Who triggered this build From 348dc860edf3d57d4a85abb8b09a03c2e3965c01 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 09:33:01 +0530 Subject: [PATCH 10/60] Checkout block --- Jenkinsfile | 10 +++++++++- deploy.sh | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 919a205..daaf72f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -17,11 +17,19 @@ pipeline { stages { + stage('0. Checkoout') { + steps { + checkout scm + } + } + + + stage('1. Extract Parameters from Merge') { steps { script { // Get branch name (strip "origin/" prefix) - env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' + env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') // Get full commit hash env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() // Who triggered this build diff --git a/deploy.sh b/deploy.sh index bc7f758..1fc9af1 100644 --- a/deploy.sh +++ b/deploy.sh @@ -31,7 +31,7 @@ echo "===============================" # ── Step 3: Go to workspace and build WAR ───────────────── cd "$WORKSPACE" -echo "🔨 Starting Maven WAR build..." +echo "🔨 Starting Maven WAR build...." mvn clean package -DskipTests # ── Step 4: Confirm WAR was created ─────────────────────── From 074e9f5815e7be8e15b43d67261a3e88c1a69dc3 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 11:44:50 +0530 Subject: [PATCH 11/60] Workspace-params --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index daaf72f..4e8e93c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { environment { // Where params file will be saved on Jenkins VM - PARAMS_FILE = "/tmp/jenkins-params/${env.JOB_NAME}-build-params.env" + PARAMS_FILE = "env.WORKSPACE/build-params.env" } stages { From e860332ac7da233fe8e56cf15db5aae063817cc6 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 11:47:43 +0530 Subject: [PATCH 12/60] updated Build Name --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4e8e93c..87bdaa4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,7 +29,7 @@ pipeline { steps { script { // Get branch name (strip "origin/" prefix) - env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') + env.BRANCH = env.GIT_BRANCH.replaceAll('origin/', '') // Get full commit hash env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() // Who triggered this build From d99ad730a971dedab299bf2335abe279d52d8c17 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 12:44:48 +0530 Subject: [PATCH 13/60] updated Build Name --- Jenkinsfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 87bdaa4..764efed 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { // Get branch name (strip "origin/" prefix) env.BRANCH = env.GIT_BRANCH.replaceAll('origin/', '') // Get full commit hash - env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + env.COMMIT_HASH = env.GIT_COMMIT // Who triggered this build env.BUILD_CAUSE = 'jenkins-bot' // For this learning exercise, always do a Build @@ -55,7 +55,7 @@ pipeline { steps { script { // Create the directory if it doesn't exist - sh "mkdir -p \$(dirname ${env.PARAMS_FILE})" + mkdir -p \$(dirname ${env.PARAMS_FILE}) // Write all params — shell script will read this writeFile file: env.PARAMS_FILE, text: """\ @@ -68,7 +68,7 @@ BUILD_CAUSE=${env.BUILD_CAUSE} WORKSPACE=${env.WORKSPACE} """ echo "✅ Params written to: ${env.PARAMS_FILE}" - sh "cat ${env.PARAMS_FILE}" + cat ${env.PARAMS_FILE} } } } @@ -76,10 +76,9 @@ WORKSPACE=${env.WORKSPACE} stage('3. Build WAR') { steps { script { - sh """ - echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - """ + echo "📦 Reading params and building WAR..." + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + } } } From 6463146540da6c79136508fa8d00d1e5c25b40f2 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 13:53:29 +0530 Subject: [PATCH 14/60] updated Build Name --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 764efed..78cdb5c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,7 +55,7 @@ pipeline { steps { script { // Create the directory if it doesn't exist - mkdir -p \$(dirname ${env.PARAMS_FILE}) + mkdir -p $(dirname ${env.PARAMS_FILE}) // Write all params — shell script will read this writeFile file: env.PARAMS_FILE, text: """\ From 10e1a455378986689114391738f3b82cab380e67 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:01:14 +0530 Subject: [PATCH 15/60] updated Build Name --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 78cdb5c..351bdba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { environment { // Where params file will be saved on Jenkins VM - PARAMS_FILE = "env.WORKSPACE/build-params.env" + PARAMS_FILE = "${env.WORKSPACE}/build-params.env" } stages { @@ -55,7 +55,7 @@ pipeline { steps { script { // Create the directory if it doesn't exist - mkdir -p $(dirname ${env.PARAMS_FILE}) + writeFile file: env.PARAMS_FILE, text: """\ // Write all params — shell script will read this writeFile file: env.PARAMS_FILE, text: """\ @@ -68,7 +68,7 @@ BUILD_CAUSE=${env.BUILD_CAUSE} WORKSPACE=${env.WORKSPACE} """ echo "✅ Params written to: ${env.PARAMS_FILE}" - cat ${env.PARAMS_FILE} + echo readFile("${env.WORKSPACE}/build-params.env") } } } From 41476e597b99602d3a57d9c1b5fe8b481786b782 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:04:46 +0530 Subject: [PATCH 16/60] updated Build Name --- Jenkinsfile | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 351bdba..9cb33a3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,14 +59,16 @@ pipeline { // Write all params — shell script will read this writeFile file: env.PARAMS_FILE, text: """\ -JOB_NAME=${env.JOB_NAME} -BRANCH=${env.BRANCH} -COMMIT_HASH=${env.COMMIT_HASH} -BUILD_ENV=${env.BUILD_ENV} -REQUIRED=${env.REQUIRED} -BUILD_CAUSE=${env.BUILD_CAUSE} -WORKSPACE=${env.WORKSPACE} -""" + + JOB_NAME=${env.JOB_NAME} + BRANCH=${env.BRANCH} + COMMIT_HASH=${env.COMMIT_HASH} + BUILD_ENV=${env.BUILD_ENV} + REQUIRED=${env.REQUIRED} + BUILD_CAUSE=${env.BUILD_CAUSE} + WORKSPACE=${env.WORKSPACE} + + """ echo "✅ Params written to: ${env.PARAMS_FILE}" echo readFile("${env.WORKSPACE}/build-params.env") } From c3842cf7c736f8efe93cad4a07e0d7a851c893ce Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:09:52 +0530 Subject: [PATCH 17/60] updated Build Name1 --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9cb33a3..896adf3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -100,6 +100,7 @@ pipeline { } failure { echo "❌ Build FAILED — Check console output above" + } } } -} \ No newline at end of file + \ No newline at end of file From 763c569e53c2810be15a42d0df0402eda32c317e Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:10:33 +0530 Subject: [PATCH 18/60] updated Build Name1 --- Jenkinsfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 896adf3..9a5d7f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,14 +2,14 @@ pipeline { agent any - // triggers { - // pollSCM('* * * * *') - // } - triggers { - githubPush() // auto-triggers when code is pushed/merged + pollSCM('* * * * *') } + // triggers { + // githubPush() // auto-triggers when code is pushed/merged + // } + environment { // Where params file will be saved on Jenkins VM PARAMS_FILE = "${env.WORKSPACE}/build-params.env" From c6dd2f97e279d7291c12b8c463028094b5679aa4 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:11:25 +0530 Subject: [PATCH 19/60] updated Build Name1 --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9a5d7f4..b6fcb67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -103,4 +103,4 @@ pipeline { } } } - \ No newline at end of file +} \ No newline at end of file From b37c186de0e2a3ca23056dd5db8e5e4d31ab72ff Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:18:53 +0530 Subject: [PATCH 20/60] UPDATES --- Jenkinsfile | 75 ++++++++++++++--------------------------------------- 1 file changed, 19 insertions(+), 56 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b6fcb67..ba19f7b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,52 +1,36 @@ pipeline { agent any - triggers { pollSCM('* * * * *') } - // triggers { - // githubPush() // auto-triggers when code is pushed/merged - // } - environment { - // Where params file will be saved on Jenkins VM PARAMS_FILE = "${env.WORKSPACE}/build-params.env" } stages { - stage('0. Checkoout') { + stage('0. Checkout') { steps { checkout scm } } - - - - stage('1. Extract Parameters from Merge') { + + stage('1. Extract Parameters') { steps { script { - // Get branch name (strip "origin/" prefix) - env.BRANCH = env.GIT_BRANCH.replaceAll('origin/', '') - // Get full commit hash + env.BRANCH = env.GIT_BRANCH.replaceAll('origin/', '') env.COMMIT_HASH = env.GIT_COMMIT - // Who triggered this build - env.BUILD_CAUSE = 'jenkins-bot' - // For this learning exercise, always do a Build - env.REQUIRED = 'Build' - env.BUILD_ENV = 'uat' + env.BUILD_CAUSE = 'jenkins-bot' + env.REQUIRED = 'Build' + env.BUILD_ENV = 'uat' - echo """ - ======= Parameters Extracted ======= - BRANCH : ${env.BRANCH} - COMMIT_HASH : ${env.COMMIT_HASH} - BUILD_CAUSE : ${env.BUILD_CAUSE} - REQUIRED : ${env.REQUIRED} - BUILD_ENV : ${env.BUILD_ENV} - ==================================== - """ + echo "BRANCH : ${env.BRANCH}" + echo "COMMIT_HASH : ${env.COMMIT_HASH}" + echo "BUILD_CAUSE : ${env.BUILD_CAUSE}" + echo "REQUIRED : ${env.REQUIRED}" + echo "BUILD_ENV : ${env.BUILD_ENV}" } } } @@ -54,53 +38,32 @@ pipeline { stage('2. Write Params to File') { steps { script { - // Create the directory if it doesn't exist - writeFile file: env.PARAMS_FILE, text: """\ - - // Write all params — shell script will read this - writeFile file: env.PARAMS_FILE, text: """\ - - JOB_NAME=${env.JOB_NAME} - BRANCH=${env.BRANCH} - COMMIT_HASH=${env.COMMIT_HASH} - BUILD_ENV=${env.BUILD_ENV} - REQUIRED=${env.REQUIRED} - BUILD_CAUSE=${env.BUILD_CAUSE} - WORKSPACE=${env.WORKSPACE} - - """ - echo "✅ Params written to: ${env.PARAMS_FILE}" - echo readFile("${env.WORKSPACE}/build-params.env") + writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" + echo "Params written:" + echo readFile(env.PARAMS_FILE) } } } stage('3. Build WAR') { steps { - script { - echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - - } + sh '#!/bin/sh -e\ncd ${WORKSPACE} && mvn clean package -DskipTests' } } stage('4. Archive WAR') { steps { - // Save the WAR as a Jenkins build artifact archiveArtifacts artifacts: 'target/*.war', fingerprint: true - echo "✅ WAR archived successfully" } } } post { success { - echo "🎉 Build SUCCESS — Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" + echo "SUCCESS" } failure { - echo "❌ Build FAILED — Check console output above" - } + echo "FAILED" } } -} \ No newline at end of file +} \ No newline at end of file From b7a4950d65317a4041f7613726e436415de60c2c Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:35:38 +0530 Subject: [PATCH 21/60] UPDATES --- Jenkinsfile | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ba19f7b..7e013fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,8 +1,12 @@ pipeline { agent any + // triggers { + // pollSCM('* * * * *') + // } + triggers { - pollSCM('* * * * *') + githubPush() // auto-triggers when code is pushed/merged } environment { @@ -26,11 +30,15 @@ pipeline { env.REQUIRED = 'Build' env.BUILD_ENV = 'uat' - echo "BRANCH : ${env.BRANCH}" - echo "COMMIT_HASH : ${env.COMMIT_HASH}" - echo "BUILD_CAUSE : ${env.BUILD_CAUSE}" - echo "REQUIRED : ${env.REQUIRED}" - echo "BUILD_ENV : ${env.BUILD_ENV}" + echo """ + ======= Parameters Extracted ======= + BRANCH : ${env.BRANCH} + COMMIT_HASH : ${env.COMMIT_HASH} + BUILD_CAUSE : ${env.BUILD_CAUSE} + REQUIRED : ${env.REQUIRED} + BUILD_ENV : ${env.BUILD_ENV} + ==================================== + """ } } } @@ -47,23 +55,30 @@ pipeline { stage('3. Build WAR') { steps { - sh '#!/bin/sh -e\ncd ${WORKSPACE} && mvn clean package -DskipTests' + script { + sh """ + echo "📦 Reading params and building WAR..." + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + """ + } } } stage('4. Archive WAR') { steps { + // Save the WAR as a Jenkins build artifact archiveArtifacts artifacts: 'target/*.war', fingerprint: true + echo "✅ WAR archived successfully" } } } post { success { - echo "SUCCESS" + echo "🎉 Build SUCCESS — Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" } failure { - echo "FAILED" + echo "❌ Build FAILED — Check console output above" } } } \ No newline at end of file From 1964d2276daf853b1ca4f6832069e4007e5ef12f Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:40:46 +0530 Subject: [PATCH 22/60] UPDATES --- Jenkinsfile | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 7e013fe..6dc531b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -56,10 +56,9 @@ pipeline { stage('3. Build WAR') { steps { script { - sh """ - echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - """ + echo "📦 Reading params and building WAR..." + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + } } } From 4d45812ca91e2b68644900975a8d459c8ad00498 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 14:52:54 +0530 Subject: [PATCH 23/60] UPDATES --- Jenkinsfile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6dc531b..e41198c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -57,8 +57,12 @@ pipeline { steps { script { echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - + + ['bin/bash', '-x', + "${env.WORKSPACE}/deploy.sh", + "${env.WORKSPACE}/build-params.env" + ].execute().waitForProcessOutput(System.out, System.err) + } } } From 8b64c995c9aec05d72290d9ab86f317204393d53 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 15:00:51 +0530 Subject: [PATCH 24/60] UPDATES --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e41198c..6aa2fa7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { script { echo "📦 Reading params and building WAR..." - ['bin/bash', '-x', + ['/bin/bash', '-x', "${env.WORKSPACE}/deploy.sh", "${env.WORKSPACE}/build-params.env" ].execute().waitForProcessOutput(System.out, System.err) From cc74d7f10977513719a58f0e4108b6add4e8baa7 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 15:05:51 +0530 Subject: [PATCH 25/60] UPDATES --- Jenkinsfile | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6aa2fa7..5570e14 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,18 +54,34 @@ pipeline { } stage('3. Build WAR') { - steps { - script { - echo "📦 Reading params and building WAR..." + steps { + script { + echo "Reading params and building WAR..." - ['/bin/bash', '-x', - "${env.WORKSPACE}/deploy.sh", - "${env.WORKSPACE}/build-params.env" - ].execute().waitForProcessOutput(System.out, System.err) - - } + def process = [ + '/bin/bash', + '-x', + "${env.WORKSPACE}/deploy.sh", + "${env.WORKSPACE}/build-params.env" + ].execute() + + // Capture output without System.out / System.err + def stdout = new StringBuilder() + def stderr = new StringBuilder() + process.waitForProcessOutput(stdout, stderr) + + // Print using Jenkins echo — no System access needed + if (stdout) echo "OUTPUT:\n${stdout}" + if (stderr) echo "STDERR:\n${stderr}" + + if (process.exitValue() != 0) { + error("deploy.sh failed with exit code: ${process.exitValue()}") } + + echo "deploy.sh completed successfully" } + } +} stage('4. Archive WAR') { steps { From a596a3631115b935b195442f41d98fb3aa48c1a1 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 16:13:46 +0530 Subject: [PATCH 26/60] UPDATES --- Jenkinsfile | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5570e14..eca0e96 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,35 +54,12 @@ pipeline { } stage('3. Build WAR') { - steps { - script { - echo "Reading params and building WAR..." - - def process = [ - '/bin/bash', - '-x', - "${env.WORKSPACE}/deploy.sh", - "${env.WORKSPACE}/build-params.env" - ].execute() - - // Capture output without System.out / System.err - def stdout = new StringBuilder() - def stderr = new StringBuilder() - process.waitForProcessOutput(stdout, stderr) - - // Print using Jenkins echo — no System access needed - if (stdout) echo "OUTPUT:\n${stdout}" - if (stderr) echo "STDERR:\n${stderr}" - - if (process.exitValue() != 0) { - error("deploy.sh failed with exit code: ${process.exitValue()}") + steps { + script { + sh "bash -x ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}" + } } - - echo "deploy.sh completed successfully" } - } -} - stage('4. Archive WAR') { steps { // Save the WAR as a Jenkins build artifact From a9a856131d09f8dc7864aa3e48164174fcd1eef2 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 17:00:10 +0530 Subject: [PATCH 27/60] UPDATES --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eca0e96..2da4dfd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,9 +55,9 @@ pipeline { stage('3. Build WAR') { steps { - script { - sh "bash -x ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}" - } + + echo "📦 Reading params and building WAR..." + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} } } stage('4. Archive WAR') { From 59215cb3e196aaf58fa656c1c10ad1446f829f01 Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 17:02:45 +0530 Subject: [PATCH 28/60] UPDATES --- Jenkinsfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2da4dfd..fba6be9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,13 @@ pipeline { agent any - // triggers { - // pollSCM('* * * * *') - // } - triggers { - githubPush() // auto-triggers when code is pushed/merged + pollSCM('* * * * *') } + + // triggers { + // githubPush() // auto-triggers when code is pushed/merged + // } environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" @@ -55,9 +55,9 @@ pipeline { stage('3. Build WAR') { steps { - + echo "📦 Reading params and building WAR..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + sh "bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}" } } stage('4. Archive WAR') { From d67adc61562ba144743bb76540ec26de538b282a Mon Sep 17 00:00:00 2001 From: praveen Date: Fri, 10 Apr 2026 17:05:45 +0530 Subject: [PATCH 29/60] UPDATES --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index fba6be9..40b67e9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,6 +55,10 @@ pipeline { stage('3. Build WAR') { steps { + sh """ + chmod +x ${env.WORKSPACE}/deploy.sh + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + """ echo "📦 Reading params and building WAR..." sh "bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}" From 81c28615776fad8472c37cf3b8a7e63fc5629b41 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 11:27:04 +0530 Subject: [PATCH 30/60] SH Modify --- Jenkinsfile | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 40b67e9..ad5d53d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,16 +1,17 @@ pipeline { agent any - triggers { - pollSCM('* * * * *') - } - // triggers { - // githubPush() // auto-triggers when code is pushed/merged + // pollSCM('* * * * *') // } + + triggers { + githubPush() // auto-triggers when code is pushed/merged + } environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" + } stages { @@ -55,13 +56,9 @@ pipeline { stage('3. Build WAR') { steps { - sh """ - chmod +x ${env.WORKSPACE}/deploy.sh - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - """ - + echo "📦 Reading params and building WAR..." - sh "bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}" + sh ' ./${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}' } } stage('4. Archive WAR') { From 1a749817dd05f5c94ff9fc3c5fea3bd64a24e5e3 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 11:30:58 +0530 Subject: [PATCH 31/60] SH Modify --- Jenkinsfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ad5d53d..35e86bb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,9 +58,12 @@ pipeline { steps { echo "📦 Reading params and building WAR..." - sh ' ./${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE}' + sh """ + bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + """ } } + stage('4. Archive WAR') { steps { // Save the WAR as a Jenkins build artifact From 3fae6e4f69e819ad750c442eeae8a17a4db1ab52 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 12:05:34 +0530 Subject: [PATCH 32/60] SH Modify --- Jenkinsfile | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 35e86bb..c9a603d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,18 +1,16 @@ pipeline { agent any - // triggers { - // pollSCM('* * * * *') - // } - triggers { - githubPush() // auto-triggers when code is pushed/merged + pollSCM('* * * * *') } + + - environment { - PARAMS_FILE = "${env.WORKSPACE}/build-params.env" + // environment { + // PARAMS_FILE = "${env.WORKSPACE}/build-params.env" - } + // } stages { @@ -47,9 +45,9 @@ pipeline { stage('2. Write Params to File') { steps { script { - writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" + writeFile file: $PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" echo "Params written:" - echo readFile(env.PARAMS_FILE) + echo readFile($PARAMS_FILE) } } } @@ -59,7 +57,7 @@ pipeline { echo "📦 Reading params and building WAR..." sh """ - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} + bash $DEPLOY_SCRIPT $PARAMS_FILE """ } } From 9c7d2bbd8d29a38e9525d0795d0650226aaf2f5a Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 12:13:34 +0530 Subject: [PATCH 33/60] SH Modify --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c9a603d..317089b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -45,9 +45,9 @@ pipeline { stage('2. Write Params to File') { steps { script { - writeFile file: $PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" + writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" echo "Params written:" - echo readFile($PARAMS_FILE) + echo readFile(env.PARAMS_FILE) } } } From 4d5cf6d4507904de97f7f8026302f8f56cb0927d Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 13:09:52 +0530 Subject: [PATCH 34/60] SH Modify --- Jenkinsfile | 54 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 317089b..0466f29 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,10 +7,11 @@ pipeline { - // environment { - // PARAMS_FILE = "${env.WORKSPACE}/build-params.env" + environment { + PARAMS_FILE = "${env.WORKSPACE}/build-params.env" + DEPLOY_SCRIPT = "${WORKSPACE}/deploy.sh" - // } + } stages { @@ -53,23 +54,44 @@ pipeline { } stage('3. Build WAR') { + steps { - - echo "📦 Reading params and building WAR..." - sh """ - bash $DEPLOY_SCRIPT $PARAMS_FILE - """ - } - } - - stage('4. Archive WAR') { - steps { - // Save the WAR as a Jenkins build artifact - archiveArtifacts artifacts: 'target/*.war', fingerprint: true - echo "✅ WAR archived successfully" + + script { + println "Before sh step" + + try { + sh ''' + echo "Inside shell" + whoami + pwd + ''' + } catch (e) { + println "Shell failed: ${e}" + } + + println "After sh step" } } } + // stage('3. Build WAR') { + // steps { + + // echo "📦 Reading params and building WAR..." + // sh """ + // bash $DEPLOY_SCRIPT $PARAMS_FILE + // """ + // } + // } + + // stage('4. Archive WAR') { + // steps { + // // Save the WAR as a Jenkins build artifact + // archiveArtifacts artifacts: 'target/*.war', fingerprint: true + // echo "✅ WAR archived successfully" + // } + // } + // } post { success { From 21295c2475c330d98cc4bbb09277eac35d1f688e Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 13:18:17 +0530 Subject: [PATCH 35/60] SH Modify --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0466f29..63608ba 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,9 +1,9 @@ pipeline { agent any - triggers { - pollSCM('* * * * *') - } + // triggers { + // pollSCM('* * * * *') + // } From d3aac087e7f29c00183dbc9f3f13cf7cf95d3f02 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 14:34:54 +0530 Subject: [PATCH 36/60] SH Modify --- Jenkinsfile | 46 +++++++++++----------------------------------- 1 file changed, 11 insertions(+), 35 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 63608ba..32add74 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,12 +1,7 @@ pipeline { agent any - // triggers { - // pollSCM('* * * * *') - // } - - environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" DEPLOY_SCRIPT = "${WORKSPACE}/deploy.sh" @@ -53,10 +48,8 @@ pipeline { } } - stage('3. Build WAR') { - + stage('3. Sample sh') { steps { - script { println "Before sh step" @@ -65,40 +58,23 @@ pipeline { echo "Inside shell" whoami pwd - ''' + ''' } catch (e) { - println "Shell failed: ${e}" + println "Shell failed: $(e)" + } + println "After sh step" } - - println "After sh step" } } - } - // stage('3. Build WAR') { - // steps { - - // echo "📦 Reading params and building WAR..." - // sh """ - // bash $DEPLOY_SCRIPT $PARAMS_FILE - // """ - // } - // } - - // stage('4. Archive WAR') { - // steps { - // // Save the WAR as a Jenkins build artifact - // archiveArtifacts artifacts: 'target/*.war', fingerprint: true - // echo "✅ WAR archived successfully" - // } - // } - // } - post { + post{ success { - echo "🎉 Build SUCCESS — Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" + echo "🎉 Build SUCCESS - Branch : ${env.Branch} | Commit: ${env.COMMIT_HASH}" } failure { - echo "❌ Build FAILED — Check console output above" + echo "❌ Build FAILED - Check console output above" } } -} \ No newline at end of file + +} + From 8e42dc6d53ff368808182db4b725919357a1ccc6 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 14:37:16 +0530 Subject: [PATCH 37/60] SH Modify --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 32add74..18d0c23 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -60,7 +60,7 @@ pipeline { pwd ''' } catch (e) { - println "Shell failed: $(e)" + println "Shell failed: ${e}" } println "After sh step" } From a14c900dfd74b792bd04cbedc6648d17af855024 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 14:40:26 +0530 Subject: [PATCH 38/60] SH Modify --- Jenkinsfile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 18d0c23..b513ffb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,7 +66,7 @@ pipeline { } } } - + } post{ success { echo "🎉 Build SUCCESS - Branch : ${env.Branch} | Commit: ${env.COMMIT_HASH}" @@ -76,5 +76,4 @@ pipeline { } } -} - +} \ No newline at end of file From 56b2084a9df86d44f2fead12a6b4893409f71665 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 15:45:27 +0530 Subject: [PATCH 39/60] SH Modify --- Jenkinsfile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b513ffb..47c6911 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,9 +55,12 @@ pipeline { try { sh ''' + set -x + echo "Hello World" echo "Inside shell" - whoami - pwd + echo "User: $(whoami)" + + ''' } catch (e) { println "Shell failed: ${e}" From c5b7a88add08deb546697fc254a7beb9d884715d Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 16:50:05 +0530 Subject: [PATCH 40/60] War Generation groovy --- Jenkinsfile | 104 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 34 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 47c6911..da8a96b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,11 +1,12 @@ pipeline { agent any - + triggers { + pollSCM('* * * * *') + } + environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" - DEPLOY_SCRIPT = "${WORKSPACE}/deploy.sh" - } stages { @@ -25,15 +26,11 @@ pipeline { env.REQUIRED = 'Build' env.BUILD_ENV = 'uat' - echo """ - ======= Parameters Extracted ======= - BRANCH : ${env.BRANCH} - COMMIT_HASH : ${env.COMMIT_HASH} - BUILD_CAUSE : ${env.BUILD_CAUSE} - REQUIRED : ${env.REQUIRED} - BUILD_ENV : ${env.BUILD_ENV} - ==================================== - """ + echo "BRANCH : ${env.BRANCH}" + echo "COMMIT_HASH : ${env.COMMIT_HASH}" + echo "BUILD_CAUSE : ${env.BUILD_CAUSE}" + echo "REQUIRED : ${env.REQUIRED}" + echo "BUILD_ENV : ${env.BUILD_ENV}" } } } @@ -41,42 +38,81 @@ pipeline { stage('2. Write Params to File') { steps { script { - writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" - echo "Params written:" - echo readFile(env.PARAMS_FILE) + // Step 1 — Write params file + writeFile file: env.PARAMS_FILE, + text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" + + // Step 2 — Verify params file written + if (fileExists(env.PARAMS_FILE)) { + echo "Params file written successfully" + echo readFile(env.PARAMS_FILE) + } else { + error("Params file not found: ${env.PARAMS_FILE}") + } } } } - stage('3. Sample sh') { + stage('3. Build WAR') { steps { script { - println "Before sh step" - - try { - sh ''' - set -x - echo "Hello World" - echo "Inside shell" - echo "User: $(whoami)" - - - ''' - } catch (e) { - println "Shell failed: ${e}" + // Step 3 — Print params (replaces bash echo block) + echo "===============================" + echo "JOB_NAME : ${env.JOB_NAME}" + echo "BRANCH : ${env.BRANCH}" + echo "COMMIT_HASH : ${env.COMMIT_HASH}" + echo "BUILD_ENV : ${env.BUILD_ENV}" + echo "REQUIRED : ${env.REQUIRED}" + echo "WORKSPACE : ${env.WORKSPACE}" + echo "===============================" + + // Step 4 — Run Maven build + // This is the only sh we cannot avoid + echo "Starting Maven WAR build..." + sh "cd ${env.WORKSPACE} && mvn clean package -DskipTests" + + // Step 5 — Confirm WAR was created (replaces bash if block) + def warFile = "${env.WORKSPACE}/target/SampleWebApp.war" + if (fileExists(warFile)) { + echo "WAR built successfully: ${warFile}" + } else { + error("WAR file not found after build!") + } + + // Step 6 — Copy WAR to deploy dir (replaces bash cp block) + def shortHash = env.COMMIT_HASH.take(7) + def deployDir = "/home/praveen/app_scripts" + def destWarName = "SampleWebApp-${shortHash}.war" + def destWar = "${deployDir}/${destWarName}" + + // Copy using Groovy file operations — no sh needed + new File(destWar).bytes = new File(warFile).bytes + + // Step 7 — Confirm copy worked + if (fileExists(destWar)) { + echo "WAR copied successfully to: ${destWar}" + } else { + error("WAR copy failed!") } - println "After sh step" } } } + + stage('4. Archive WAR') { + steps { + archiveArtifacts artifacts: 'target/*.war', + fingerprint: true + echo "WAR archived successfully" + } + } } - post{ + + post { success { - echo "🎉 Build SUCCESS - Branch : ${env.Branch} | Commit: ${env.COMMIT_HASH}" + echo "SUCCESS - Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" } failure { - echo "❌ Build FAILED - Check console output above" + echo "FAILED - Check console output" } } - } \ No newline at end of file From ac8b99404fda91c3be519e68663da94ed33ed567 Mon Sep 17 00:00:00 2001 From: praveen Date: Mon, 13 Apr 2026 16:57:39 +0530 Subject: [PATCH 41/60] War Generation groovy --- Jenkinsfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index da8a96b..0181252 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -86,7 +86,13 @@ pipeline { def destWar = "${deployDir}/${destWarName}" // Copy using Groovy file operations — no sh needed - new File(destWar).bytes = new File(warFile).bytes + fileOperations([ + + fileCopyOperation( + includes: warFile, + targetLocation: destWar + ) + ]) // Step 7 — Confirm copy worked if (fileExists(destWar)) { From 1e17ef5906a6e189c0378ce5f85d5234945f5acc Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 11:04:00 +0530 Subject: [PATCH 42/60] Forced bash --- Jenkinsfile | 131 ++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 70 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0181252..e14c252 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,12 +1,16 @@ pipeline { agent any - triggers { - pollSCM('* * * * *') - } + // triggers { + // pollSCM('* * * * *') + // } + + environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" + DEPLOY_SCRIPT = "${WORKSPACE}/deploy.sh" + } stages { @@ -26,11 +30,15 @@ pipeline { env.REQUIRED = 'Build' env.BUILD_ENV = 'uat' - echo "BRANCH : ${env.BRANCH}" - echo "COMMIT_HASH : ${env.COMMIT_HASH}" - echo "BUILD_CAUSE : ${env.BUILD_CAUSE}" - echo "REQUIRED : ${env.REQUIRED}" - echo "BUILD_ENV : ${env.BUILD_ENV}" + echo """ + ======= Parameters Extracted ======= + BRANCH : ${env.BRANCH} + COMMIT_HASH : ${env.COMMIT_HASH} + BUILD_CAUSE : ${env.BUILD_CAUSE} + REQUIRED : ${env.REQUIRED} + BUILD_ENV : ${env.BUILD_ENV} + ==================================== + """ } } } @@ -38,87 +46,70 @@ pipeline { stage('2. Write Params to File') { steps { script { - // Step 1 — Write params file - writeFile file: env.PARAMS_FILE, - text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" - - // Step 2 — Verify params file written - if (fileExists(env.PARAMS_FILE)) { - echo "Params file written successfully" - echo readFile(env.PARAMS_FILE) - } else { - error("Params file not found: ${env.PARAMS_FILE}") - } + writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" + echo "Params written:" + echo readFile(env.PARAMS_FILE) } } } stage('3. Build WAR') { steps { - script { - // Step 3 — Print params (replaces bash echo block) - echo "===============================" - echo "JOB_NAME : ${env.JOB_NAME}" - echo "BRANCH : ${env.BRANCH}" - echo "COMMIT_HASH : ${env.COMMIT_HASH}" - echo "BUILD_ENV : ${env.BUILD_ENV}" - echo "REQUIRED : ${env.REQUIRED}" - echo "WORKSPACE : ${env.WORKSPACE}" - echo "===============================" - - // Step 4 — Run Maven build - // This is the only sh we cannot avoid - echo "Starting Maven WAR build..." - sh "cd ${env.WORKSPACE} && mvn clean package -DskipTests" - - // Step 5 — Confirm WAR was created (replaces bash if block) - def warFile = "${env.WORKSPACE}/target/SampleWebApp.war" - if (fileExists(warFile)) { - echo "WAR built successfully: ${warFile}" - } else { - error("WAR file not found after build!") - } - - // Step 6 — Copy WAR to deploy dir (replaces bash cp block) - def shortHash = env.COMMIT_HASH.take(7) - def deployDir = "/home/praveen/app_scripts" - def destWarName = "SampleWebApp-${shortHash}.war" - def destWar = "${deployDir}/${destWarName}" - - // Copy using Groovy file operations — no sh needed - fileOperations([ - - fileCopyOperation( - includes: warFile, - targetLocation: destWar - ) - ]) - - // Step 7 — Confirm copy worked - if (fileExists(destWar)) { - echo "WAR copied successfully to: ${destWar}" - } else { - error("WAR copy failed!") - } - } + sh(script: """ + echo "Inside Shell" + whoami + pwd + """, shell: '/bin/sh') } } + // stage('3. Build WAR') { + + // steps { + + // script { + // println "Before sh step" + + // try { + // sh(""" + // echo "Inside shell" + // whoami + // pwd + // ''', shell: '/bin/sh') + // } catch (e) { + // println "Shell failed: ${e}" + // } + + // println "After sh step" + // } + // } + // } + + // stage('3. Build WAR') { + // steps { + + // echo "📦 Reading params and building WAR..." + // sh(script: """ + // bash $DEPLOY_SCRIPT $PARAMS_FILE + // """, shell: '/bin/sh') + // } + // } + stage('4. Archive WAR') { steps { - archiveArtifacts artifacts: 'target/*.war', - fingerprint: true - echo "WAR archived successfully" + // Save the WAR as a Jenkins build artifact + archiveArtifacts artifacts: 'target/*.war', fingerprint: true + echo "✅ WAR archived successfully" } } } post { success { - echo "SUCCESS - Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" + echo "🎉 Build SUCCESS — Branch: ${env.BRANCH} | Commit: ${env.COMMIT_HASH}" } failure { - echo "FAILED - Check console output" + echo "❌ Build FAILED — Check console output above" } } } \ No newline at end of file From b654313a8b879b3a872cb534aa9536272e3e81ea Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 12:36:00 +0530 Subject: [PATCH 43/60] Test --- Jenkinsfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e14c252..671d9ae 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -53,15 +53,15 @@ pipeline { } } - stage('3. Build WAR') { - steps { - sh(script: """ - echo "Inside Shell" - whoami - pwd - """, shell: '/bin/sh') - } - } + // stage('3. Build WAR') { + // steps { + // sh(script: """ + // echo "Inside Shell" + // whoami + // pwd + // """, shell: '/bin/sh') + // } + // } // stage('3. Build WAR') { @@ -85,15 +85,15 @@ pipeline { // } // } - // stage('3. Build WAR') { - // steps { + stage('3. Build WAR') { + steps { - // echo "📦 Reading params and building WAR..." - // sh(script: """ - // bash $DEPLOY_SCRIPT $PARAMS_FILE - // """, shell: '/bin/sh') - // } - // } + echo "📦 Reading params and building WAR..." + sh """ + bash $DEPLOY_SCRIPT $PARAMS_FILE + """ + } + } stage('4. Archive WAR') { steps { From 8416a1e5facc7d7532d62be4d0071fd9062a6237 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 12:42:15 +0530 Subject: [PATCH 44/60] testing --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 671d9ae..452e864 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -99,6 +99,7 @@ pipeline { steps { // Save the WAR as a Jenkins build artifact archiveArtifacts artifacts: 'target/*.war', fingerprint: true + echo "✅ WAR archived successfully" } } From 64843e94acc1526e87a0c91593de087333d30aac Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 12:46:02 +0530 Subject: [PATCH 45/60] testing --- Jenkinsfile | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 452e864..5d3d85f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -95,11 +95,19 @@ pipeline { } } - stage('4. Archive WAR') { + stage('4. Sleep'){ + steps { + sh 'echo Hello' + sh 'sleep 30' + } + } + + + stage('5. Archive WAR') { steps { // Save the WAR as a Jenkins build artifact archiveArtifacts artifacts: 'target/*.war', fingerprint: true - + echo "✅ WAR archived successfully" } } From 02e7198b19b81475c9f9968badabef341848ff1f Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 12:47:52 +0530 Subject: [PATCH 46/60] testing --- Jenkinsfile | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5d3d85f..3c348f7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -85,15 +85,15 @@ pipeline { // } // } - stage('3. Build WAR') { - steps { + // stage('3. Build WAR') { + // steps { - echo "📦 Reading params and building WAR..." - sh """ - bash $DEPLOY_SCRIPT $PARAMS_FILE - """ - } - } + // echo "📦 Reading params and building WAR..." + // sh """ + // bash $DEPLOY_SCRIPT $PARAMS_FILE + // """ + // } + // } stage('4. Sleep'){ steps { @@ -103,15 +103,15 @@ pipeline { } - stage('5. Archive WAR') { - steps { - // Save the WAR as a Jenkins build artifact - archiveArtifacts artifacts: 'target/*.war', fingerprint: true + // stage('5. Archive WAR') { + // steps { + // // Save the WAR as a Jenkins build artifact + // archiveArtifacts artifacts: 'target/*.war', fingerprint: true - echo "✅ WAR archived successfully" - } - } - } + // echo "✅ WAR archived successfully" + // } + // } + // } post { success { From 882406ad68581e42e23c03510548e5016ba0fd22 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 12:50:09 +0530 Subject: [PATCH 47/60] testing --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3c348f7..1571e67 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -95,7 +95,7 @@ pipeline { // } // } - stage('4. Sleep'){ + stage('4. Sleep') { steps { sh 'echo Hello' sh 'sleep 30' From 66e487110ab0745afddded2a63d070f9caf0190b Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 13:06:08 +0530 Subject: [PATCH 48/60] testing --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1571e67..ed4a962 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,6 @@ pipeline { } stages { - stage('0. Checkout') { steps { checkout scm @@ -111,7 +110,7 @@ pipeline { // echo "✅ WAR archived successfully" // } // } - // } + } post { success { From d5ed4f72d8f6eb13ef82a4be059039edad2c3389 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 15:45:57 +0530 Subject: [PATCH 49/60] GitHub actions tes --- Jenkinsfile | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ed4a962..f54f646 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -84,32 +84,30 @@ pipeline { // } // } - // stage('3. Build WAR') { - // steps { - - // echo "📦 Reading params and building WAR..." - // sh """ - // bash $DEPLOY_SCRIPT $PARAMS_FILE - // """ - // } - // } - - stage('4. Sleep') { + stage('3. Build WAR') { steps { - sh 'echo Hello' - sh 'sleep 30' - } - } + echo "📦 Reading params and building WAR..." + sh """ + /bin/sh < Date: Tue, 14 Apr 2026 15:52:07 +0530 Subject: [PATCH 50/60] GitHub Actions testing --- .github/workflows/main.yml | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7060c24 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,58 @@ +name: Build WAR + +on: + push: + branches: + - uat + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up environment variables + run: | + echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "COMMIT_HASH=${GITHUB_SHA}" >> $GITHUB_ENV + echo "BUILD_CAUSE=github-actions" >> $GITHUB_ENV + echo "REQUIRED=Build" >> $GITHUB_ENV + echo "BUILD_ENV=uat" >> $GITHUB_ENV + echo "JOB_NAME=${{ github.repository }}" >> $GITHUB_ENV + echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV + + - name: Create params file + run: | + cat < build-params.env + JOB_NAME=$JOB_NAME + BRANCH=$BRANCH + COMMIT_HASH=$COMMIT_HASH + BUILD_ENV=$BUILD_ENV + REQUIRED=$REQUIRED + BUILD_CAUSE=$BUILD_CAUSE + WORKSPACE=$WORKSPACE + EOF + + echo "===== Params File =====" + cat build-params.env + + - name: Make deploy.sh executable + run: chmod +x deploy.sh + + - name: Run deploy.sh (WAR build) + run: | + set -e + set -x + + bash ./deploy.sh build-params.env + + - name: Archive WAR artifact + uses: actions/upload-artifact@v4 + with: + name: app-war + path: | + **/*.war From 72b02c5be6d3c81f698ad84d5248aae37e37ac12 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 15:55:51 +0530 Subject: [PATCH 51/60] GitHub Actions testing --- .github/workflows/{main.yml => building_war.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{main.yml => building_war.yml} (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/building_war.yml similarity index 100% rename from .github/workflows/main.yml rename to .github/workflows/building_war.yml From 7eb9befcee39ae252fc427e5860b5c65baa113d5 Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 16:00:43 +0530 Subject: [PATCH 52/60] GitHub Actions testing --- .github/workflows/building_war.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/building_war.yml b/.github/workflows/building_war.yml index 7060c24..2f58509 100644 --- a/.github/workflows/building_war.yml +++ b/.github/workflows/building_war.yml @@ -3,7 +3,7 @@ name: Build WAR on: push: branches: - - uat + - UAT workflow_dispatch: jobs: From 7b81f6bf3c466fb3c82cd86368815608e203e8ff Mon Sep 17 00:00:00 2001 From: praveen Date: Tue, 14 Apr 2026 16:11:13 +0530 Subject: [PATCH 53/60] GitHub Actions testing --- deploy.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deploy.sh b/deploy.sh index 1fc9af1..d4862df 100644 --- a/deploy.sh +++ b/deploy.sh @@ -45,11 +45,15 @@ else exit 1 fi -DEPLOY_DIR="/home/praveen/app_scripts/" +DEPLOY_DIR="$WORKSPACE/app_scripts" + +# 🔥 REQUIRED +mkdir -p "$DEPLOY_DIR" + cp "$WAR_FILE" "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" if [[ -f "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" ]]; then - echo "✅ WAR copied successfully!" + echo "✅ WAR copied successfully" else echo "❌ WAR copy failed" exit 1 From 3bb52b5d818913e95c0af8ec37fcc23999d1f14c Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 12:38:46 +0530 Subject: [PATCH 54/60] Shared Library --- Jenkinsfile | 226 ++++++++++++++++++++++++++++++++++------------------ deploy.sh | 8 +- 2 files changed, 149 insertions(+), 85 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f54f646..4b340fd 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,121 +1,189 @@ +@Library('cicd-library') _ pipeline { agent any - // triggers { - // pollSCM('* * * * *') - // } - - + triggers { + githubPush() + } environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" - DEPLOY_SCRIPT = "${WORKSPACE}/deploy.sh" - } +# tools { +# maven 'Maven-3.9.14' // must match Jenkins tool name EXACTLY +#} + stages { - stage('0. Checkout') { - steps { - checkout scm - } - } stage('1. Extract Parameters') { steps { script { - env.BRANCH = env.GIT_BRANCH.replaceAll('origin/', '') - env.COMMIT_HASH = env.GIT_COMMIT - env.BUILD_CAUSE = 'jenkins-bot' - env.REQUIRED = 'Build' - env.BUILD_ENV = 'uat' + env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' + env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() + env.BUILD_CAUSE = 'jenkins-bot' + env.REQUIRED = 'Build' + env.BUILD_ENV = 'uat' echo """ - ======= Parameters Extracted ======= - BRANCH : ${env.BRANCH} - COMMIT_HASH : ${env.COMMIT_HASH} - BUILD_CAUSE : ${env.BUILD_CAUSE} - REQUIRED : ${env.REQUIRED} - BUILD_ENV : ${env.BUILD_ENV} - ==================================== - """ +======= Parameters ======= +BRANCH : ${env.BRANCH} +COMMIT_HASH : ${env.COMMIT_HASH} +BUILD_ENV : ${env.BUILD_ENV} +========================== +""" } } } - stage('2. Write Params to File') { + stage('2. Create Params File') { steps { - script { - writeFile file: env.PARAMS_FILE, text: "JOB_NAME=${env.JOB_NAME}\nBRANCH=${env.BRANCH}\nCOMMIT_HASH=${env.COMMIT_HASH}\nBUILD_ENV=${env.BUILD_ENV}\nREQUIRED=${env.REQUIRED}\nBUILD_CAUSE=${env.BUILD_CAUSE}\nWORKSPACE=${env.WORKSPACE}\n" - echo "Params written:" - echo readFile(env.PARAMS_FILE) - } + writeFile file: env.PARAMS_FILE, text: """\ +JOB_NAME=${env.JOB_NAME} +BRANCH=${env.BRANCH} +COMMIT_HASH=${env.COMMIT_HASH} +BUILD_ENV=${env.BUILD_ENV} +REQUIRED=${env.REQUIRED} +BUILD_CAUSE=${env.BUILD_CAUSE} +WORKSPACE=${env.WORKSPACE} +""" + sh "cat ${env.PARAMS_FILE}" } } - // stage('3. Build WAR') { - // steps { - // sh(script: """ - // echo "Inside Shell" - // whoami - // pwd - // """, shell: '/bin/sh') - // } - // } - - // stage('3. Build WAR') { - - // steps { - - // script { - // println "Before sh step" - - // try { - // sh(""" - // echo "Inside shell" - // whoami - // pwd - // ''', shell: '/bin/sh') - // } catch (e) { - // println "Shell failed: ${e}" - // } - - // println "After sh step" - // } - // } - // } - - stage('3. Build WAR') { + stage('3. Build WAR') { steps { - echo "📦 Reading params and building WAR..." - sh """ - /bin/sh < Date: Thu, 16 Apr 2026 12:58:55 +0530 Subject: [PATCH 55/60] Shared Library --- Jenkinsfile | 166 ++++------------------------------------------------ 1 file changed, 13 insertions(+), 153 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4b340fd..aeb4a27 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,4 +1,5 @@ @Library('cicd-library') _ + pipeline { agent any @@ -10,180 +11,39 @@ pipeline { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" } -# tools { -# maven 'Maven-3.9.14' // must match Jenkins tool name EXACTLY -#} - stages { - stage('1. Extract Parameters') { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Prepare Params') { steps { script { env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() - env.BUILD_CAUSE = 'jenkins-bot' - env.REQUIRED = 'Build' - env.BUILD_ENV = 'uat' - echo """ -======= Parameters ======= -BRANCH : ${env.BRANCH} -COMMIT_HASH : ${env.COMMIT_HASH} -BUILD_ENV : ${env.BUILD_ENV} -========================== -""" + env.REQUIRED = "Build" + env.BUILD_ENV = "uat" } - } - } - stage('2. Create Params File') { - steps { writeFile file: env.PARAMS_FILE, text: """\ JOB_NAME=${env.JOB_NAME} BRANCH=${env.BRANCH} COMMIT_HASH=${env.COMMIT_HASH} BUILD_ENV=${env.BUILD_ENV} REQUIRED=${env.REQUIRED} -BUILD_CAUSE=${env.BUILD_CAUSE} WORKSPACE=${env.WORKSPACE} """ - sh "cat ${env.PARAMS_FILE}" } } - stage('3. Build WAR') { + stage('Run Deployment') { steps { - - - script { - #def mvnHome = tool '3.9.14' - #sh """ - #export PATH=${mvnHome}/bin:\$PATH - #echo "Using Maven from: ${mvnHome}" - #mvn -v - - echo "📦 Running deployment script..." - bash ${env.WORKSPACE}/deploy.sh ${env.PARAMS_FILE} - """ - } - } - } - - stage('4. Archive WAR') { - steps { - archiveArtifacts artifacts: 'target/*.war', fingerprint: true - echo "✅ WAR archived" + deploy("${env.PARAMS_FILE}") // ✅ THIS is correct usage } } } - - post { - success { - echo "🎉 SUCCESS" - } - failure { - echo "❌ FAILED" - } - } -} - - - - -// pipeline { -// agent any - -// triggers { -// githubPush() -// } - -// environment { -// PARAMS_FILE = "/tmp/jenkins-params/${env.JOB_NAME}-build-params.env" -// BUILD_ENV = "uat" -// REQUIRED = "Build" -// BUILD_CAUSE = "jenkins-bot" -// } - -// stages { - -// stage('1. Extract Parameters') { -// steps { -// script { -// // safer branch detection -// env.BRANCH = sh( -// script: "git rev-parse --abbrev-ref HEAD", -// returnStdout: true -// ).trim() - -// env.COMMIT_HASH = sh( -// script: "git rev-parse HEAD", -// returnStdout: true -// ).trim() - -// echo """ -// ======= Parameters Extracted ======= -// BRANCH : ${env.BRANCH} -// COMMIT_HASH : ${env.COMMIT_HASH} -// BUILD_CAUSE : ${env.BUILD_CAUSE} -// REQUIRED : ${env.REQUIRED} -// BUILD_ENV : ${env.BUILD_ENV} -// ==================================== -// """ -// } -// } -// } - -// stage('2. Write Params File') { -// steps { -// script { -// sh """ -// mkdir -p \$(dirname ${PARAMS_FILE}) -// """ - -// writeFile file: PARAMS_FILE, text: """\ -// JOB_NAME=${env.JOB_NAME} -// BRANCH=${env.BRANCH} -// COMMIT_HASH=${env.COMMIT_HASH} -// BUILD_ENV=${env.BUILD_ENV} -// REQUIRED=${env.REQUIRED} -// BUILD_CAUSE=${env.BUILD_CAUSE} -// WORKSPACE=${env.WORKSPACE} -// """ - -// echo "📄 Params written to: ${PARAMS_FILE}" -// sh "cat ${PARAMS_FILE}" -// } -// } -// } - -// stage('3. Execute deploy.sh') { -// steps { -// sh """ -// set -e -// set -x - -// echo "🚀 Running deploy.sh..." - -// chmod +x ${WORKSPACE}/deploy.sh -// ${WORKSPACE}/deploy.sh ${PARAMS_FILE} -// """ -// } -// } - -// stage('4. Archive WAR') { -// steps { -// archiveArtifacts artifacts: '**/*.war', fingerprint: true -// echo "✅ WAR archived successfully" -// } -// } -// } - -// post { -// success { -// echo "🎉 SUCCESS — ${env.BRANCH} @ ${env.COMMIT_HASH}" -// } -// failure { -// echo "❌ FAILED — Check logs" -// } -// } -// } +} \ No newline at end of file From 55335dfb4b9c0efcf53494e86d5b5c079b5eda6a Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 13:01:56 +0530 Subject: [PATCH 56/60] Shared Library --- .github/workflows/building_war.yml | 58 ------------------------------ 1 file changed, 58 deletions(-) delete mode 100644 .github/workflows/building_war.yml diff --git a/.github/workflows/building_war.yml b/.github/workflows/building_war.yml deleted file mode 100644 index 2f58509..0000000 --- a/.github/workflows/building_war.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Build WAR - -on: - push: - branches: - - UAT - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up environment variables - run: | - echo "BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV - echo "COMMIT_HASH=${GITHUB_SHA}" >> $GITHUB_ENV - echo "BUILD_CAUSE=github-actions" >> $GITHUB_ENV - echo "REQUIRED=Build" >> $GITHUB_ENV - echo "BUILD_ENV=uat" >> $GITHUB_ENV - echo "JOB_NAME=${{ github.repository }}" >> $GITHUB_ENV - echo "WORKSPACE=${{ github.workspace }}" >> $GITHUB_ENV - - - name: Create params file - run: | - cat < build-params.env - JOB_NAME=$JOB_NAME - BRANCH=$BRANCH - COMMIT_HASH=$COMMIT_HASH - BUILD_ENV=$BUILD_ENV - REQUIRED=$REQUIRED - BUILD_CAUSE=$BUILD_CAUSE - WORKSPACE=$WORKSPACE - EOF - - echo "===== Params File =====" - cat build-params.env - - - name: Make deploy.sh executable - run: chmod +x deploy.sh - - - name: Run deploy.sh (WAR build) - run: | - set -e - set -x - - bash ./deploy.sh build-params.env - - - name: Archive WAR artifact - uses: actions/upload-artifact@v4 - with: - name: app-war - path: | - **/*.war From 9b95440a5d5c318cc8565ae705ab832b5dd1f786 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 13:40:40 +0530 Subject: [PATCH 57/60] Shared Library --- deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy.sh b/deploy.sh index 1fc9af1..14d81f1 100644 --- a/deploy.sh +++ b/deploy.sh @@ -45,7 +45,7 @@ else exit 1 fi -DEPLOY_DIR="/home/praveen/app_scripts/" +DEPLOY_DIR="$WORKSPACE/app_scripts/" cp "$WAR_FILE" "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" if [[ -f "$DEPLOY_DIR/SampleWebAPP-${COMMIT_HASH:0:7}.war" ]]; then From 9b57409c4b28b39fefb4931a0794910139999890 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 18:07:52 +0530 Subject: [PATCH 58/60] Parmameters --- Jenkinsfile | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index aeb4a27..e314839 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,12 @@ pipeline { githubPush() } + parameters { + string(name: 'BRANCH', defaultValue: '', description: 'Git branch to deploy') + choice(name: 'BUILD_ENV', choices: ['uat', 'stage', 'prod'], description: 'Target environment') + choice(name: 'REQUIRED', choices: ['Build', 'Files_Copy', 'Build_And_Files_Copy'], description: 'Action') + } + environment { PARAMS_FILE = "${env.WORKSPACE}/build-params.env" } @@ -19,14 +25,28 @@ pipeline { } } + stage('Validate Input') { + steps { + script { + if (!params.BRANCH || !params.BUILD_ENV) { + error "❌ Missing BRANCH or BUILD_ENV" + } + + echo "🚀 Branch: ${params.BRANCH}" + echo "🌍 Env: ${params.BUILD_ENV}" + echo "⚙️ Action: ${params.REQUIRED}" + } + } + } + stage('Prepare Params') { steps { script { - env.BRANCH = env.GIT_BRANCH?.replaceAll('origin/', '') ?: 'master' + env.BRANCH = params.BRANCH env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() - env.REQUIRED = "Build" - env.BUILD_ENV = "uat" + env.REQUIRED = params.REQUIRED + env.BUILD_ENV = params.Env } writeFile file: env.PARAMS_FILE, text: """\ @@ -42,7 +62,7 @@ WORKSPACE=${env.WORKSPACE} stage('Run Deployment') { steps { - deploy("${env.PARAMS_FILE}") // ✅ THIS is correct usage + deploy("${env.PARAMS_FILE}") } } } From 41ce92945ce123c59cbda975f600dd820ed2822b Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 18:17:42 +0530 Subject: [PATCH 59/60] Parmameters --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e314839..040ea82 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -8,9 +8,9 @@ pipeline { } parameters { - string(name: 'BRANCH', defaultValue: '', description: 'Git branch to deploy') - choice(name: 'BUILD_ENV', choices: ['uat', 'stage', 'prod'], description: 'Target environment') - choice(name: 'REQUIRED', choices: ['Build', 'Files_Copy', 'Build_And_Files_Copy'], description: 'Action') + string(name: 'BRANCH', defaultValue: '', description: 'Git branch') + choice(name: 'BUILD_ENV', choices: ['uat', 'stage', 'prod'], description: 'Environment') + choice(name: 'REQUIRED', choices: ['Build', 'Deploy'], description: 'Action') } environment { From cc15d1768b408317057bf5cc0d25d43e526f47d9 Mon Sep 17 00:00:00 2001 From: praveen Date: Thu, 16 Apr 2026 18:59:04 +0530 Subject: [PATCH 60/60] Parmameters --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 040ea82..86e64ac 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -42,11 +42,11 @@ pipeline { stage('Prepare Params') { steps { script { - env.BRANCH = params.BRANCH + env.BRANCH = params.BRANCH ?: env.GIT_BRANCH?.replaceAll('origin/', '') env.COMMIT_HASH = sh(script: 'git rev-parse HEAD', returnStdout: true).trim() env.REQUIRED = params.REQUIRED - env.BUILD_ENV = params.Env + env.BUILD_ENV = params.BUILD_ENV } writeFile file: env.PARAMS_FILE, text: """\