From 8d8fc2ca5b65ce51872bed1074b9c2bb9646f32a Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 14:37:34 -0500 Subject: [PATCH 01/31] add jenkinsfile --- jenkinsfile | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 jenkinsfile diff --git a/jenkinsfile b/jenkinsfile new file mode 100644 index 0000000..9899624 --- /dev/null +++ b/jenkinsfile @@ -0,0 +1,19 @@ +pipeline { + agent any + + stages { + stage('Build') { + steps { + echo 'Building..' + sh""" + ls + """ + } + } + stage('Deploy') { + steps { + echo 'Deploying....' + } + } + } +} \ No newline at end of file From ce1066f47bf64926d438700ac9d64f520a16e1a9 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 14:52:56 -0500 Subject: [PATCH 02/31] modified jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 9899624..623748e 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -6,7 +6,7 @@ pipeline { steps { echo 'Building..' sh""" - ls + ls src """ } } From 6546bbbbfc6ccd169ba44db3ce5059083cf73ae1 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 15:02:53 -0500 Subject: [PATCH 03/31] Rename jenkinsfile to Jenkinsfile --- jenkinsfile => Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename jenkinsfile => Jenkinsfile (99%) diff --git a/jenkinsfile b/Jenkinsfile similarity index 99% rename from jenkinsfile rename to Jenkinsfile index 623748e..0bc6bf7 100644 --- a/jenkinsfile +++ b/Jenkinsfile @@ -16,4 +16,4 @@ pipeline { } } } -} \ No newline at end of file +} From 7d9cf9de8d1c0953f9fc7096165948bc8e83c7d5 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 15:33:10 -0500 Subject: [PATCH 04/31] modified jenkinsfile --- jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkinsfile b/jenkinsfile index 623748e..da7c1b6 100644 --- a/jenkinsfile +++ b/jenkinsfile @@ -6,7 +6,7 @@ pipeline { steps { echo 'Building..' sh""" - ls src + mvn package """ } } From 7112cdcaa3f0fbf6c74b7a416c48544ecdba923e Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 15:54:01 -0500 Subject: [PATCH 05/31] modified pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9e1759e..4025a53 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.web.cal WebAppCal war - 0.0.6 + 17 WebAppCal Maven Webapp http://maven.apache.org From 3136d953efbaa38924e860c29539da09f9b1c5eb Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 16:04:02 -0500 Subject: [PATCH 06/31] modified pom.xml --- pom.xml | 61 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 4025a53..e9e73e8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,30 +1,57 @@ - + + 4.0.0 com.web.cal WebAppCal + 0.0.6 war - 17 WebAppCal Maven Webapp http://maven.apache.org + + + 17 + 17 + UTF-8 + + junit junit - 4.8.2 + 4.13.2 test - - - javax.servlet - servlet-api - 2.5 - - - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - + + javax.servlet + servlet-api + 2.5 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + 17 + 17 + + + + + + + + releases + http://52.204.135.48:8081/nexus/content/repositories/releases + + + + From 9fe7b5976808688cba493141b47b61b03c53be36 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 16:11:09 -0500 Subject: [PATCH 07/31] modified pom.xml --- pom.xml | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index e9e73e8..b8c5abb 100644 --- a/pom.xml +++ b/pom.xml @@ -1,36 +1,26 @@ - - + 4.0.0 com.web.cal WebAppCal - 0.0.6 war + 0.0.7 WebAppCal Maven Webapp http://maven.apache.org - - - 17 - 17 - UTF-8 - - junit junit - 4.13.2 + 4.8.2 test - - javax.servlet - servlet-api - 2.5 - provided - - + + + javax.servlet + servlet-api + 2.5 + + @@ -43,15 +33,12 @@ 17 + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + - - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - - From 7bb93e69eda83dc4412c4eaad45fcc6ccc99b880 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Mon, 28 Apr 2025 16:32:29 -0500 Subject: [PATCH 08/31] added artifact on jenkinsfilel --- Jenkinsfile | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4b8120a..f09de70 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -5,14 +5,26 @@ pipeline { stage('Build') { steps { echo 'Building..' - sh""" - mvn package + sh """ + mvn package """ } } + + stage('Upload Artifact') { + steps { + echo 'Uploading to S3...' + sh """ + cd target + aws s3 cp WebAppCal-*.war s3://project1-joke-s3/ + """ + } + } + stage('Deploy') { steps { echo 'Deploying....' + // Add actual deployment commands here } } } From 0785943b413d02423954c50ad0fd729684a2b36a Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 08:22:01 -0500 Subject: [PATCH 09/31] added clean artifact on jenkinsfilel --- Jenkinsfile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f09de70..e15fe4d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,22 +2,26 @@ pipeline { agent any stages { + stage('Clean Old Artifacts') { + steps { + sh 'rm -rf target' + } + } + stage('Build') { steps { echo 'Building..' - sh """ - mvn package - """ + sh 'mvn package' } } stage('Upload Artifact') { steps { echo 'Uploading to S3...' - sh """ + sh ''' cd target aws s3 cp WebAppCal-*.war s3://project1-joke-s3/ - """ + ''' } } From 79b161d958cdb955e2f818666b71b87ff46b55b9 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 09:39:14 -0500 Subject: [PATCH 10/31] added clean artifact on jenkinsfilel --- Jenkinsfile | 12 ++++++++---- ansible/ec2.yml | 11 +++++++++++ ansible/playbook.yml | 9 +++++++++ group_vars/webservers.yml | 3 +++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 ansible/ec2.yml create mode 100644 ansible/playbook.yml create mode 100644 group_vars/webservers.yml diff --git a/Jenkinsfile b/Jenkinsfile index e15fe4d..24a6eaf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,11 +25,15 @@ pipeline { } } - stage('Deploy') { + + + stage('Deploy') { steps { - echo 'Deploying....' - // Add actual deployment commands here + sh""" + cd ansible + ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" + """ } } } -} +} \ No newline at end of file diff --git a/ansible/ec2.yml b/ansible/ec2.yml new file mode 100644 index 0000000..d98e37b --- /dev/null +++ b/ansible/ec2.yml @@ -0,0 +1,11 @@ +# demo.aws_ec2.yml +plugin: amazon.aws.aws_ec2 + +regions: + - us-east-1 + +groups: + webservers: "'project1-app' in tags.Name" + +hostnames: + - private-ip-address \ No newline at end of file diff --git a/ansible/playbook.yml b/ansible/playbook.yml new file mode 100644 index 0000000..1a2f6c3 --- /dev/null +++ b/ansible/playbook.yml @@ -0,0 +1,9 @@ +--- +- name: Update web servers + hosts: webservers + remote_user: ec2-user + become: true + + tasks: + - name: Ping servers + ansible.builtin.ping: diff --git a/group_vars/webservers.yml b/group_vars/webservers.yml new file mode 100644 index 0000000..56e3abc --- /dev/null +++ b/group_vars/webservers.yml @@ -0,0 +1,3 @@ +ansible_user: ec2-user +ansible_ssh_private_key_file: ~/.ssh/server-key +ansible_ssh_common_args: "-o StrictHostKeyChecking=no" \ No newline at end of file From 178afd5cc72d051c43ac3f94daf50cb6075df608 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 10:20:32 -0500 Subject: [PATCH 11/31] modified playbookl --- ansible/playbook.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 1a2f6c3..6e6026f 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,8 +1,6 @@ --- - name: Update web servers hosts: webservers - remote_user: ec2-user - become: true tasks: - name: Ping servers From 4e9b833ef8cadca7ffd022a8d2a43b9e056bfa90 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:10:11 -0500 Subject: [PATCH 12/31] modified playbookl and jenkisfile --- Jenkinsfile | 44 +++++++++++++++++++++++++++++++------------- ansible/playbook.yml | 9 +++++++-- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 24a6eaf..9446c5b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,11 @@ pipeline { agent any + environment { + BUCKET_NAME = 'project1-joke-s3' + ARTIFACT_NAME = '' // Placeholder, will be set dynamically + } + stages { stage('Clean Old Artifacts') { steps { @@ -10,30 +15,43 @@ pipeline { stage('Build') { steps { - echo 'Building..' + echo 'Building...' sh 'mvn package' } } - stage('Upload Artifact') { + stage('Set Artifact Name') { steps { - echo 'Uploading to S3...' - sh ''' - cd target - aws s3 cp WebAppCal-*.war s3://project1-joke-s3/ - ''' + script { + // Get the actual filename and store it + def artifactName = sh( + script: "ls target/WebAppCal-*.war | xargs -n 1 basename", + returnStdout: true + ).trim() + + env.ARTIFACT_NAME = artifactName + } } } - + stage('Upload Artifact') { + steps { + echo "Uploading ${env.ARTIFACT_NAME} to S3..." + sh """ + aws s3 cp target/${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/ + """ + } + } - stage('Deploy') { + stage('Deploy') { steps { - sh""" - cd ansible - ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" + echo "Deploying ${env.ARTIFACT_NAME} using Ansible..." + sh """ + cd ansible + ansible-playbook -i aws_ec2.yml playbook.yml \ + -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" """ } } } -} \ No newline at end of file +} diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 6e6026f..bd9a930 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -3,5 +3,10 @@ hosts: webservers tasks: - - name: Ping servers - ansible.builtin.ping: + - name: Get Artifact + amazon.aws.s3_object: + bucket: "{{ BUCKET_NAME }}" + object: "{{ ARTIFACT_NAME }}" + dest: "~/{{ ARTIFACT_NAME }}" + mode: get + delegate_to: localhost From ce8c43988ff2273600783d48ee4b5afaee9a177a Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:13:34 -0500 Subject: [PATCH 13/31] modified playbookl and jenkisfile --- Jenkinsfile | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9446c5b..4ef27ff 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,40 +3,53 @@ pipeline { environment { BUCKET_NAME = 'project1-joke-s3' - ARTIFACT_NAME = '' // Placeholder, will be set dynamically + ARTIFACT_NAME = '' // Will be set dynamically } stages { + stage('Clean Old Artifacts') { steps { + echo '๐Ÿงน Cleaning old build artifacts...' sh 'rm -rf target' } } stage('Build') { steps { - echo 'Building...' + echo '๐Ÿ”จ Building project...' sh 'mvn package' } } + stage('Verify Artifact') { + steps { + echo '๐Ÿ” Listing target directory to check artifact...' + sh 'ls -lh target' + } + } + stage('Set Artifact Name') { steps { script { - // Get the actual filename and store it def artifactName = sh( - script: "ls target/WebAppCal-*.war | xargs -n 1 basename", + script: "ls target/WebAppCal-*.war 2>/dev/null | xargs -n 1 basename || true", returnStdout: true ).trim() - + + if (!artifactName) { + error("โŒ No WAR artifact found in target/. Check Maven build output.") + } + env.ARTIFACT_NAME = artifactName + echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" } } } stage('Upload Artifact') { steps { - echo "Uploading ${env.ARTIFACT_NAME} to S3..." + echo "โ˜๏ธ Uploading ${env.ARTIFACT_NAME} to S3 bucket ${env.BUCKET_NAME}..." sh """ aws s3 cp target/${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/ """ @@ -45,7 +58,7 @@ pipeline { stage('Deploy') { steps { - echo "Deploying ${env.ARTIFACT_NAME} using Ansible..." + echo "๐Ÿš€ Deploying ${env.ARTIFACT_NAME} using Ansible..." sh """ cd ansible ansible-playbook -i aws_ec2.yml playbook.yml \ @@ -55,3 +68,4 @@ pipeline { } } } + From 9a638f65495f716b574bdab20ebcac28c9f45500 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:17:58 -0500 Subject: [PATCH 14/31] modified playbookl and jenkisfile --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4ef27ff..fe0097d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -33,11 +33,11 @@ pipeline { steps { script { def artifactName = sh( - script: "ls target/WebAppCal-*.war 2>/dev/null | xargs -n 1 basename || true", + script: "basename $(ls target/WebAppCal-*.war 2>/dev/null || true)", returnStdout: true ).trim() - if (!artifactName) { + if (!artifactName || artifactName == 'null') { error("โŒ No WAR artifact found in target/. Check Maven build output.") } @@ -69,3 +69,4 @@ pipeline { } } + From 419948664d90b98c036fa74f2b6da100c838ab62 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:21:24 -0500 Subject: [PATCH 15/31] modified playbookl and jenkisfile --- Jenkinsfile | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fe0097d..35e5cd7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,23 +29,24 @@ pipeline { } } - stage('Set Artifact Name') { - steps { - script { - def artifactName = sh( - script: "basename $(ls target/WebAppCal-*.war 2>/dev/null || true)", - returnStdout: true - ).trim() - - if (!artifactName || artifactName == 'null') { - error("โŒ No WAR artifact found in target/. Check Maven build output.") - } + stage('Set Artifact Name') { + steps { + script { + def artifactName = sh( + script: 'basename $(ls target/WebAppCal-*.war 2>/dev/null || true)', + returnStdout: true + ).trim() - env.ARTIFACT_NAME = artifactName - echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" - } + if (!artifactName || artifactName == 'null') { + error("โŒ No WAR artifact found in target/. Check Maven build output.") } + + env.ARTIFACT_NAME = artifactName + echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" } + } +} + stage('Upload Artifact') { steps { From d006a72c198e6d2f912262adb1db3b2760dffd56 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:27:29 -0500 Subject: [PATCH 16/31] modified playbookl and jenkisfile --- Jenkinsfile | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 35e5cd7..6e896fb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -29,24 +29,25 @@ pipeline { } } - stage('Set Artifact Name') { - steps { - script { - def artifactName = sh( - script: 'basename $(ls target/WebAppCal-*.war 2>/dev/null || true)', - returnStdout: true - ).trim() + stage('Set Artifact Name') { + steps { + script { + // Use find to locate the WAR file and assign it to the artifactName variable + def artifactName = sh( + script: "find target -type f -name 'WebAppCal-*.war' -print -quit", + returnStdout: true + ).trim() - if (!artifactName || artifactName == 'null') { - error("โŒ No WAR artifact found in target/. Check Maven build output.") - } + if (!artifactName) { + error("โŒ No WAR artifact found in target/. Check Maven build output.") + } - env.ARTIFACT_NAME = artifactName - echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" + // Extract the filename from the path + env.ARTIFACT_NAME = artifactName.split("/").last() + echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" + } + } } - } -} - stage('Upload Artifact') { steps { @@ -62,8 +63,7 @@ pipeline { echo "๐Ÿš€ Deploying ${env.ARTIFACT_NAME} using Ansible..." sh """ cd ansible - ansible-playbook -i aws_ec2.yml playbook.yml \ - -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" + ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" """ } } From cae745ebc86c70f24f14113d2908284a16dbc0cc Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:54:08 -0500 Subject: [PATCH 17/31] modified playbookl and jenkisfile --- Jenkinsfile | 41 ++++++++++++----------------------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6e896fb..3d2f682 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,42 +22,27 @@ pipeline { } } - stage('Verify Artifact') { - steps { - echo '๐Ÿ” Listing target directory to check artifact...' - sh 'ls -lh target' - } - } - - stage('Set Artifact Name') { + stage('Upload Artifact') { steps { script { - // Use find to locate the WAR file and assign it to the artifactName variable + // Find the WAR file def artifactName = sh( - script: "find target -type f -name 'WebAppCal-*.war' -print -quit", + script: "cd target && ls webappcalf*.war", returnStdout: true ).trim() - - if (!artifactName) { - error("โŒ No WAR artifact found in target/. Check Maven build output.") - } - - // Extract the filename from the path - env.ARTIFACT_NAME = artifactName.split("/").last() - echo "โœ… Found artifact: ${env.ARTIFACT_NAME}" + + // Set the artifact name as an environment variable + env.ARTIFACT_NAME = artifactName + + // Upload it to S3 (replace BUCKET_NAME with your actual bucket name) + sh """ + cd target + aws s3 cp ${env.ARTIFACT_NAME} s3://${BUCKET_NAME}/ + """ } } } - stage('Upload Artifact') { - steps { - echo "โ˜๏ธ Uploading ${env.ARTIFACT_NAME} to S3 bucket ${env.BUCKET_NAME}..." - sh """ - aws s3 cp target/${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/ - """ - } - } - stage('Deploy') { steps { echo "๐Ÿš€ Deploying ${env.ARTIFACT_NAME} using Ansible..." @@ -69,5 +54,3 @@ pipeline { } } } - - From 0d80db050675420b05b8ce73a848d17e08ac8696 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:57:19 -0500 Subject: [PATCH 18/31] modified playbookl and jenkisfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3d2f682..c89bca7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,7 +27,7 @@ pipeline { script { // Find the WAR file def artifactName = sh( - script: "cd target && ls webappcalf*.war", + script: "cd target && ls webAppcal-*.war", returnStdout: true ).trim() From 43b1cf81d92fbf48bafbac33ff0f9d9d8ef7a369 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 11:58:25 -0500 Subject: [PATCH 19/31] modified playbookl and jenkisfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c89bca7..b1b3a05 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,7 +27,7 @@ pipeline { script { // Find the WAR file def artifactName = sh( - script: "cd target && ls webAppcal-*.war", + script: "cd target && ls WebAppCal-*.war", returnStdout: true ).trim() From 95c9c3808edaa5c70c27f85d67f0ca2f68d4469a Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 12:01:44 -0500 Subject: [PATCH 20/31] modified playbookl and jenkisfile --- Jenkinsfile | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index b1b3a05..929ec1c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,18 +27,15 @@ pipeline { script { // Find the WAR file def artifactName = sh( - script: "cd target && ls WebAppCal-*.war", + script: "ls target/WebAppCal*.war", returnStdout: true ).trim() // Set the artifact name as an environment variable env.ARTIFACT_NAME = artifactName - // Upload it to S3 (replace BUCKET_NAME with your actual bucket name) - sh """ - cd target - aws s3 cp ${env.ARTIFACT_NAME} s3://${BUCKET_NAME}/ - """ + // Upload it to S3 + sh "aws s3 cp ${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/" } } } @@ -54,3 +51,4 @@ pipeline { } } } + From c31c1b05a5b9986bff32851883c2e70b9675f865 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 12:05:19 -0500 Subject: [PATCH 21/31] modified playbookl and jenkisfile --- Jenkinsfile | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 929ec1c..0115a1a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -25,16 +25,16 @@ pipeline { stage('Upload Artifact') { steps { script { - // Find the WAR file + // Find the WAR file and assign it to a Groovy variable def artifactName = sh( script: "ls target/WebAppCal*.war", returnStdout: true ).trim() - - // Set the artifact name as an environment variable - env.ARTIFACT_NAME = artifactName - - // Upload it to S3 + + // Set the artifact name as an environment variable correctly + env.ARTIFACT_NAME = "target/${artifactName}" + + // Upload it to S3 using the full path sh "aws s3 cp ${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/" } } @@ -51,4 +51,3 @@ pipeline { } } } - From 50ef3449e1f441419501a7487e04a9f60d60098e Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 12:08:52 -0500 Subject: [PATCH 22/31] modified playbookl and jenkisfile --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0115a1a..bd11218 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -31,7 +31,7 @@ pipeline { returnStdout: true ).trim() - // Set the artifact name as an environment variable correctly + // Set the artifact name correctly (no additional path) env.ARTIFACT_NAME = "target/${artifactName}" // Upload it to S3 using the full path @@ -51,3 +51,4 @@ pipeline { } } } + From 1deb3c18b6340b5b07a2a1332a50b5fe19c65ec0 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 16:28:53 -0500 Subject: [PATCH 23/31] modified playbookl and jenkisfile --- Jenkinsfile | 39 +++++++++++++++++++++------------------ ansible/playbook.yml | 14 +++++++------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index bd11218..98bf53f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,51 +1,54 @@ pipeline { agent any - environment { - BUCKET_NAME = 'project1-joke-s3' - ARTIFACT_NAME = '' // Will be set dynamically + BUCKET_NAME='project1-joke-s3' } stages { - stage('Clean Old Artifacts') { steps { - echo '๐Ÿงน Cleaning old build artifacts...' - sh 'rm -rf target' + sh""" + rm -rf target + """ } } stage('Build') { steps { - echo '๐Ÿ”จ Building project...' - sh 'mvn package' + sh""" + mvn package + """ } } stage('Upload Artifact') { steps { script { - // Find the WAR file and assign it to a Groovy variable + // Find the WAR file def artifactName = sh( - script: "ls target/WebAppCal*.war", + script: "cd target && ls WebAppCal-*.war", returnStdout: true ).trim() - // Set the artifact name correctly (no additional path) - env.ARTIFACT_NAME = "target/${artifactName}" + // Set the artifact name as an environmrnt variable + env.ARTIFACT_NAME = artifactName - // Upload it to S3 using the full path - sh "aws s3 cp ${env.ARTIFACT_NAME} s3://${env.BUCKET_NAME}/" + // upload it to s3 + sh """ + cd target + aws s3 cp ${artifactName} s3://${env.BUCKET_NAME}/ + """ } } } + + stage('Deploy') { steps { - echo "๐Ÿš€ Deploying ${env.ARTIFACT_NAME} using Ansible..." - sh """ - cd ansible - ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" + sh""" + cd ansible + ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" """ } } diff --git a/ansible/playbook.yml b/ansible/playbook.yml index bd9a930..33576be 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -3,10 +3,10 @@ hosts: webservers tasks: - - name: Get Artifact - amazon.aws.s3_object: - bucket: "{{ BUCKET_NAME }}" - object: "{{ ARTIFACT_NAME }}" - dest: "~/{{ ARTIFACT_NAME }}" - mode: get - delegate_to: localhost + - name: Get Artifact + amazon.aws.s3_object: + bucket: {{ BUCKET_NAME }} + object: {{ ARTIFACT_NAME }} + dest: ~/{ARTIFACT_NAME }}" + mode: get + delegate_to: localhost From 2ac4cb84d0c01936bf24ae73080ae5eff8b37b76 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 16:36:15 -0500 Subject: [PATCH 24/31] modified playbookl and jenkisfile --- ansible/playbook.yml | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 33576be..2be7766 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,12 +1,14 @@ --- - name: Update web servers hosts: webservers + become: yes tasks: - - name: Get Artifact - amazon.aws.s3_object: - bucket: {{ BUCKET_NAME }} - object: {{ ARTIFACT_NAME }} - dest: ~/{ARTIFACT_NAME }}" - mode: get - delegate_to: localhost + - name: Get Artifact from S3 + amazon.aws.s3_object: + bucket: "{{ BUCKET_NAME }}" + object: "{{ ARTIFACT_NAME }}" + dest: "/tmp/{{ ARTIFACT_NAME }}" + mode: get + delegate_to: localhost + From 675a4a175d6191437517243e2571c6223bb1b66c Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 16:47:44 -0500 Subject: [PATCH 25/31] DEPLOY --- ansible/playbook.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 2be7766..ec9bd80 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -12,3 +12,7 @@ mode: get delegate_to: localhost +- name: Deploy Artifact to Hosts + ansible.builtin.copy: + src: ~/"path/to/local/{{ARTIFACT_NAME}}" + dest: /home/ec2-user/apache-tomcat/webapps/"{{ARTIFACT__NAME}}" From 295655f97783a399e8d5063b9d1514cbdb24ac6f Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Tue, 29 Apr 2025 16:52:37 -0500 Subject: [PATCH 26/31] DEPLOY --- ansible/playbook.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index ec9bd80..895b2a9 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,10 +1,10 @@ --- -- name: Update web servers +- name: Deploy WAR from S3 hosts: webservers become: yes tasks: - - name: Get Artifact from S3 + - name: Download WAR file from S3 amazon.aws.s3_object: bucket: "{{ BUCKET_NAME }}" object: "{{ ARTIFACT_NAME }}" @@ -12,7 +12,9 @@ mode: get delegate_to: localhost -- name: Deploy Artifact to Hosts - ansible.builtin.copy: - src: ~/"path/to/local/{{ARTIFACT_NAME}}" - dest: /home/ec2-user/apache-tomcat/webapps/"{{ARTIFACT__NAME}}" + - name: Copy WAR file to Tomcat webapps directory + ansible.builtin.copy: + src: "/tmp/{{ ARTIFACT_NAME }}" + dest: "/opt/tomcat/webapps/{{ ARTIFACT_NAME }}" + remote_src: yes + From cb46d12aa5ed1003643a4dc63d2b3071fd48fc77 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Thu, 1 May 2025 08:35:08 -0500 Subject: [PATCH 27/31] mofified playbook --- ansible/playbook.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 895b2a9..bb24643 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -3,18 +3,21 @@ hosts: webservers become: yes + vars: + local_war_path: "{{ ansible_env.HOME }}/{{ ARTIFACT_NAME }}" + remote_tomcat_path: "/home/ec2-user/apache-tomcat/webapps/{{ ARTIFACT_NAME }}" + tasks: - - name: Download WAR file from S3 + - name: Download WAR file from S3 to localhost amazon.aws.s3_object: bucket: "{{ BUCKET_NAME }}" object: "{{ ARTIFACT_NAME }}" - dest: "/tmp/{{ ARTIFACT_NAME }}" + dest: "{{ local_war_path }}" mode: get delegate_to: localhost - - name: Copy WAR file to Tomcat webapps directory + - name: Copy WAR file from localhost to remote Tomcat webapps directory ansible.builtin.copy: - src: "/tmp/{{ ARTIFACT_NAME }}" - dest: "/opt/tomcat/webapps/{{ ARTIFACT_NAME }}" - remote_src: yes + src: "{{ local_war_path }}" + dest: "{{ remote_tomcat_path }}" From 738a9b442019bd8fe15dfecac84828091a0a020c Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Thu, 1 May 2025 08:56:04 -0500 Subject: [PATCH 28/31] mofified playbook --- Jenkinsfile | 30 +++++++----------------------- ansible/playbook.yml | 4 +++- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 98bf53f..1b61d5c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,57 +1,41 @@ pipeline { agent any environment { - BUCKET_NAME='project1-joke-s3' + BUCKET_NAME = 'project1-joke-s3' } stages { stage('Clean Old Artifacts') { steps { - sh""" - rm -rf target - """ + sh 'rm -rf target' } } stage('Build') { steps { - sh""" - mvn package - """ + sh 'mvn package' } } stage('Upload Artifact') { steps { script { - // Find the WAR file + // Find the WAR file def artifactName = sh( script: "cd target && ls WebAppCal-*.war", returnStdout: true ).trim() - // Set the artifact name as an environmrnt variable + // Export artifact name for downstream use (e.g., Ansible) env.ARTIFACT_NAME = artifactName - // upload it to s3 + // Upload to S3 sh """ - cd target - aws s3 cp ${artifactName} s3://${env.BUCKET_NAME}/ + aws s3 cp target/${artifactName} s3://${env.BUCKET_NAME}/ """ } } } - - - - stage('Deploy') { - steps { - sh""" - cd ansible - ansible-playbook -i aws_ec2.yml playbook.yml -e "BUCKET_NAME=${env.BUCKET_NAME} ARTIFACT_NAME=${env.ARTIFACT_NAME}" - """ - } - } } } diff --git a/ansible/playbook.yml b/ansible/playbook.yml index bb24643..5b03050 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -4,7 +4,7 @@ become: yes vars: - local_war_path: "{{ ansible_env.HOME }}/{{ ARTIFACT_NAME }}" + local_war_path: "/tmp/{{ ARTIFACT_NAME }}" remote_tomcat_path: "/home/ec2-user/apache-tomcat/webapps/{{ ARTIFACT_NAME }}" tasks: @@ -15,9 +15,11 @@ dest: "{{ local_war_path }}" mode: get delegate_to: localhost + run_once: true - name: Copy WAR file from localhost to remote Tomcat webapps directory ansible.builtin.copy: src: "{{ local_war_path }}" dest: "{{ remote_tomcat_path }}" + From 90cd1f7588546ffc2b859f02964f2ac6b90e68dd Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Thu, 1 May 2025 09:38:45 -0500 Subject: [PATCH 29/31] mofified playbook --- Jenkinsfile | 2 +- ansible/playbook.yml | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 1b61d5c..98a53e9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -36,6 +36,6 @@ pipeline { } } } - } + } } diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 5b03050..97258a0 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,25 +1,29 @@ --- -- name: Deploy WAR from S3 +- name: Update web servers hosts: webservers become: yes vars: - local_war_path: "/tmp/{{ ARTIFACT_NAME }}" - remote_tomcat_path: "/home/ec2-user/apache-tomcat/webapps/{{ ARTIFACT_NAME }}" + bucket_name: "project1-joke-s3" + artifact_name: "WebAppCal-0.0.7.war" + local_artifact_path: "/home/{{ lookup('env', 'USER') }}/{{ artifact_name }}" + remote_deploy_path: "/home/ec2-user/apache-tomcat/webapps/{{ artifact_name }}" tasks: - - name: Download WAR file from S3 to localhost + - name: Get Artifact from S3 to control node amazon.aws.s3_object: - bucket: "{{ BUCKET_NAME }}" - object: "{{ ARTIFACT_NAME }}" - dest: "{{ local_war_path }}" + bucket: "{{ bucket_name }}" + object: "{{ artifact_name }}" + dest: "{{ local_artifact_path }}" mode: get delegate_to: localhost run_once: true - - name: Copy WAR file from localhost to remote Tomcat webapps directory + - name: Deploy artifact to remote Tomcat server ansible.builtin.copy: - src: "{{ local_war_path }}" - dest: "{{ remote_tomcat_path }}" + src: "{{ local_artifact_path }}" + dest: "{{ remote_deploy_path }}" + mode: '0644' + From 7b9e25c7108c212998c242798cff5075d60e93a0 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Thu, 1 May 2025 09:43:18 -0500 Subject: [PATCH 30/31] mofified playbook --- ansible/playbook.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 97258a0..7d65b19 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -19,11 +19,10 @@ delegate_to: localhost run_once: true - - name: Deploy artifact to remote Tomcat server - ansible.builtin.copy: - src: "{{ local_artifact_path }}" - dest: "{{ remote_deploy_path }}" - mode: '0644' - + - name: Deploy WAR to Tomcat + copy: + src: "WebAppCal-0.0.7.war" + dest: "/home/ec2-user/apache-tomcat/webapps/WebAppCal-0.0.7.war" + mode: '0644' From b067aecaeb88de10c0aabaccc9b3cee26115a776 Mon Sep 17 00:00:00 2001 From: Dasjoke Date: Thu, 1 May 2025 09:59:16 -0500 Subject: [PATCH 31/31] mofified playbook --- ansible/playbook.yml | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/ansible/playbook.yml b/ansible/playbook.yml index 7d65b19..06b9681 100644 --- a/ansible/playbook.yml +++ b/ansible/playbook.yml @@ -1,28 +1,19 @@ --- - name: Update web servers hosts: webservers - become: yes - - vars: - bucket_name: "project1-joke-s3" - artifact_name: "WebAppCal-0.0.7.war" - local_artifact_path: "/home/{{ lookup('env', 'USER') }}/{{ artifact_name }}" - remote_deploy_path: "/home/ec2-user/apache-tomcat/webapps/{{ artifact_name }}" tasks: - - name: Get Artifact from S3 to control node - amazon.aws.s3_object: - bucket: "{{ bucket_name }}" - object: "{{ artifact_name }}" - dest: "{{ local_artifact_path }}" - mode: get - delegate_to: localhost - run_once: true + - name: Get Artifact + amazon.aws.s3_object: + bucket: "{{BUCKET_NAME}}" + object: "{{ARTIFACT_NAME}}" + dest: ~/{{ARTIFACT_NAME}} + mode: get + delegate_to: localhost - - name: Deploy WAR to Tomcat - copy: - src: "WebAppCal-0.0.7.war" - dest: "/home/ec2-user/apache-tomcat/webapps/WebAppCal-0.0.7.war" - mode: '0644' + -name: Deploy Artifact to Hosts + ansible.builtin.copy: + src: /{{ ARTIFACT_NAME }} + dest: /home/ec2-user/apache-tomcat/webapps/{{ ARTIFACT_NAME}}