From c13069b1bc245a5e7915ceae695706abcfe1b831 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 11:40:59 +0530 Subject: [PATCH 01/42] Added Jenkinsfile --- Jenkinsfile | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..8488987f4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,238 @@ +pipeline { + agent any + + environment { + IMAGE_NAME = 'website-app' + PROD_CONTAINER_NAME = 'website-prod' + DEV_CONTAINER_NAME = 'website-dev' + PROD_PORT = '82' + DEV_PORT = '8081' + } + + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + timeout(time: 30, unit: 'MINUTES') + timestamps() + } + + stages { + stage('Checkout') { + steps { + echo "Checking out code from branch: \${env.BRANCH_NAME}" + checkout scm + } + } + + stage('Validate') { + steps { + script { + echo "Validating repository structure..." + sh ''' + if [ ! -f "index.html" ]; then + echo "Error: index.html not found!" + exit 1 + fi + + if grep -q "Hello world!" index.html; then + echo "HTML content validation passed" + else + echo "Warning: Expected content not found in index.html" + fi + + echo "Repository validation completed" + ''' + } + } + } + + stage('Prepare Dockerfile') { + steps { + script { + echo "Creating Dockerfile..." + writeFile file: 'Dockerfile', + text: ''' + # Use Ubuntu as base image + FROM ubuntu:20.04 + # Prevent interactive prompts + ENV DEBIAN_FRONTEND=noninteractive + # Install Apache + RUN apt-get update && \\ + apt-get install -y apache2 && \\ + apt-get clean && \\ + rm -rf /var/lib/apt/lists/* + + # Copy website files to Apache document root + COPY . /var/www/html/ + + # Set permissions + RUN chown -R www-data:www-data /var/www/html && \\ + chmod -R 755 /var/www/html + + # Expose Apache port + EXPOSE 80 + + # Start Apache in foreground + CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] + ''' + } + } + } + + stage('Build Docker Image') { + steps { + script { + echo "Building Docker image for branch: \${env.BRANCH_NAME}" + + def imageTag = "\${env.BRANCH_NAME}-\${env.BUILD_NUMBER}" + + sh """ + docker build -t \${IMAGE_NAME}:\${imageTag} . + docker build -t \${IMAGE_NAME}:\${env.BRANCH_NAME}-latest . + + echo "Docker image built successfully: \${IMAGE_NAME}:\${imageTag}" + """ + + env.IMAGE_TAG = imageTag + } + } + } + + stage('Test Build') { + steps { + script { + echo "Testing Docker image build..." + + sh """ + docker run -d --name test-container-\${BUILD_NUMBER} \ + -p 8080:80 \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 15 + + response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + + if [ "\\$response" = "200" ]; then + echo "HTTP test passed" + else + echo "HTTP test failed" + exit 1 + fi + + content=\\$(curl -s http://localhost:8080 || echo "") + if echo "\\$content" | grep -q "Hello world!"; then + echo "Content test passed" + else + echo "Content test failed" + exit 1 + fi + + docker stop test-container-\${BUILD_NUMBER} + docker rm test-container-\${BUILD_NUMBER} + + echo "Build test completed successfully" + """ + } + } + } + + stage('Deploy') { + parallel { + stage('Deploy Development') { + when { + branch 'develop' + } + steps { + script { + echo "Deploying to Development Environment..." + + sh """ + docker stop \${DEV_CONTAINER_NAME} 2>/dev/null || true + docker rm \${DEV_CONTAINER_NAME} 2>/dev/null || true + + docker run -d --name \${DEV_CONTAINER_NAME} \ + -p \${DEV_PORT}:80 \ + \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 10 + curl -f http://localhost:\${DEV_PORT} || exit 1 + + echo "Development deployment test completed" + + docker stop \${DEV_CONTAINER_NAME} + docker rm \${DEV_CONTAINER_NAME} + + echo "Development test container cleaned up" + """ + } + } + } + + stage('Deploy Production') { + when { + branch 'master' + } + steps { + script { + echo "Deploying to Production Environment..." + + sh """ + if docker ps -q -f name=\${PROD_CONTAINER_NAME} > /dev/null 2>&1; then + echo "Backing up current production container..." + backup_name="\${PROD_CONTAINER_NAME}-backup-\\$(date +%Y%m%d-%H%M%S)" + docker stop \${PROD_CONTAINER_NAME} + docker rename \${PROD_CONTAINER_NAME} \\$backup_name + fi + + docker run -d --name \${PROD_CONTAINER_NAME} \ + -p \${PROD_PORT}:80 \ + --restart unless-stopped \ + --label "version=\${env.IMAGE_TAG}" \ + --label "deployed-by=jenkins" \ + \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 15 + + response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:\${PROD_PORT} || echo "000") + + if [ "\\$response" = "200" ]; then + echo "Production deployment successful!" + echo "Website is live at http://localhost:\${PROD_PORT}" + else + echo "Production deployment failed" + exit 1 + fi + """ + } + } + } + } + } + } + + post { + success { + script { + if (env.BRANCH_NAME == 'master') { + echo "SUCCESS: Production deployment completed on port \${env.PROD_PORT}" + } else if (env.BRANCH_NAME == 'develop') { + echo "SUCCESS: Development build completed - Ready for production" + } else { + echo "SUCCESS: Feature branch build completed" + } + } + } + + failure { + echo "FAILURE: Pipeline failed for branch \${env.BRANCH_NAME}" + } + + always { + script { + sh ''' + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Cleanup completed" + ''' + } + } + } +} \ No newline at end of file From 24bed53573c70eeccad5dbfb674d1511c33d5b1c Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 12:15:35 +0530 Subject: [PATCH 02/42] Added a.txt on develop branch --- a.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 a.txt diff --git a/a.txt b/a.txt new file mode 100644 index 000000000..18df88c63 --- /dev/null +++ b/a.txt @@ -0,0 +1 @@ +text feature From bf61cd69a42c01a3e7e3eef0d88d17c549e95a47 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 12:30:43 +0530 Subject: [PATCH 03/42] Added Jenkinsfile to develop --- Jenkinsfile | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..8488987f4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,238 @@ +pipeline { + agent any + + environment { + IMAGE_NAME = 'website-app' + PROD_CONTAINER_NAME = 'website-prod' + DEV_CONTAINER_NAME = 'website-dev' + PROD_PORT = '82' + DEV_PORT = '8081' + } + + options { + buildDiscarder(logRotator(numToKeepStr: '10')) + timeout(time: 30, unit: 'MINUTES') + timestamps() + } + + stages { + stage('Checkout') { + steps { + echo "Checking out code from branch: \${env.BRANCH_NAME}" + checkout scm + } + } + + stage('Validate') { + steps { + script { + echo "Validating repository structure..." + sh ''' + if [ ! -f "index.html" ]; then + echo "Error: index.html not found!" + exit 1 + fi + + if grep -q "Hello world!" index.html; then + echo "HTML content validation passed" + else + echo "Warning: Expected content not found in index.html" + fi + + echo "Repository validation completed" + ''' + } + } + } + + stage('Prepare Dockerfile') { + steps { + script { + echo "Creating Dockerfile..." + writeFile file: 'Dockerfile', + text: ''' + # Use Ubuntu as base image + FROM ubuntu:20.04 + # Prevent interactive prompts + ENV DEBIAN_FRONTEND=noninteractive + # Install Apache + RUN apt-get update && \\ + apt-get install -y apache2 && \\ + apt-get clean && \\ + rm -rf /var/lib/apt/lists/* + + # Copy website files to Apache document root + COPY . /var/www/html/ + + # Set permissions + RUN chown -R www-data:www-data /var/www/html && \\ + chmod -R 755 /var/www/html + + # Expose Apache port + EXPOSE 80 + + # Start Apache in foreground + CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] + ''' + } + } + } + + stage('Build Docker Image') { + steps { + script { + echo "Building Docker image for branch: \${env.BRANCH_NAME}" + + def imageTag = "\${env.BRANCH_NAME}-\${env.BUILD_NUMBER}" + + sh """ + docker build -t \${IMAGE_NAME}:\${imageTag} . + docker build -t \${IMAGE_NAME}:\${env.BRANCH_NAME}-latest . + + echo "Docker image built successfully: \${IMAGE_NAME}:\${imageTag}" + """ + + env.IMAGE_TAG = imageTag + } + } + } + + stage('Test Build') { + steps { + script { + echo "Testing Docker image build..." + + sh """ + docker run -d --name test-container-\${BUILD_NUMBER} \ + -p 8080:80 \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 15 + + response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + + if [ "\\$response" = "200" ]; then + echo "HTTP test passed" + else + echo "HTTP test failed" + exit 1 + fi + + content=\\$(curl -s http://localhost:8080 || echo "") + if echo "\\$content" | grep -q "Hello world!"; then + echo "Content test passed" + else + echo "Content test failed" + exit 1 + fi + + docker stop test-container-\${BUILD_NUMBER} + docker rm test-container-\${BUILD_NUMBER} + + echo "Build test completed successfully" + """ + } + } + } + + stage('Deploy') { + parallel { + stage('Deploy Development') { + when { + branch 'develop' + } + steps { + script { + echo "Deploying to Development Environment..." + + sh """ + docker stop \${DEV_CONTAINER_NAME} 2>/dev/null || true + docker rm \${DEV_CONTAINER_NAME} 2>/dev/null || true + + docker run -d --name \${DEV_CONTAINER_NAME} \ + -p \${DEV_PORT}:80 \ + \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 10 + curl -f http://localhost:\${DEV_PORT} || exit 1 + + echo "Development deployment test completed" + + docker stop \${DEV_CONTAINER_NAME} + docker rm \${DEV_CONTAINER_NAME} + + echo "Development test container cleaned up" + """ + } + } + } + + stage('Deploy Production') { + when { + branch 'master' + } + steps { + script { + echo "Deploying to Production Environment..." + + sh """ + if docker ps -q -f name=\${PROD_CONTAINER_NAME} > /dev/null 2>&1; then + echo "Backing up current production container..." + backup_name="\${PROD_CONTAINER_NAME}-backup-\\$(date +%Y%m%d-%H%M%S)" + docker stop \${PROD_CONTAINER_NAME} + docker rename \${PROD_CONTAINER_NAME} \\$backup_name + fi + + docker run -d --name \${PROD_CONTAINER_NAME} \ + -p \${PROD_PORT}:80 \ + --restart unless-stopped \ + --label "version=\${env.IMAGE_TAG}" \ + --label "deployed-by=jenkins" \ + \${IMAGE_NAME}:\${env.IMAGE_TAG} + + sleep 15 + + response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:\${PROD_PORT} || echo "000") + + if [ "\\$response" = "200" ]; then + echo "Production deployment successful!" + echo "Website is live at http://localhost:\${PROD_PORT}" + else + echo "Production deployment failed" + exit 1 + fi + """ + } + } + } + } + } + } + + post { + success { + script { + if (env.BRANCH_NAME == 'master') { + echo "SUCCESS: Production deployment completed on port \${env.PROD_PORT}" + } else if (env.BRANCH_NAME == 'develop') { + echo "SUCCESS: Development build completed - Ready for production" + } else { + echo "SUCCESS: Feature branch build completed" + } + } + } + + failure { + echo "FAILURE: Pipeline failed for branch \${env.BRANCH_NAME}" + } + + always { + script { + sh ''' + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Cleanup completed" + ''' + } + } + } +} \ No newline at end of file From a3cba3f50308f343bcf25372113e3b5aeb3ca65c Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 13:26:19 +0530 Subject: [PATCH 04/42] Created Dockerfile Installs Apache (apt-get install apache2). Copies your website code (including index.html) to /var/www/html. Exposes port 80. Runs Apache in the foreground. --- Dockerfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..39cc403e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use Ubuntu as base image +FROM ubuntu:20.04 + +# Prevent interactive prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install Apache +RUN apt-get update && \ + apt-get install -y apache2 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy website files to Apache document root +COPY . /var/www/html/ + +# Set permissions +RUN chown -R www-data:www-data /var/www/html && \ + chmod -R 755 /var/www/html + +# Expose Apache port +EXPOSE 80 + +# Start Apache in foreground +CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] From 95021b9e6fc3cfe6859757e49203d7b6fd79048b Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 13:29:00 +0530 Subject: [PATCH 05/42] Update Jenkinsfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit develop branch → build & test only. master branch → build, test, deploy on port 82. Website code copied to /var/www/html inside container (via Dockerfile). Cleanup logic included. --- Jenkinsfile | 209 ++++++++-------------------------------------------- 1 file changed, 30 insertions(+), 179 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8488987f4..639cf8a66 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,21 +4,13 @@ pipeline { environment { IMAGE_NAME = 'website-app' PROD_CONTAINER_NAME = 'website-prod' - DEV_CONTAINER_NAME = 'website-dev' PROD_PORT = '82' - DEV_PORT = '8081' - } - - options { - buildDiscarder(logRotator(numToKeepStr: '10')) - timeout(time: 30, unit: 'MINUTES') - timestamps() } stages { stage('Checkout') { steps { - echo "Checking out code from branch: \${env.BRANCH_NAME}" + echo "Checking out branch: ${env.BRANCH_NAME}" checkout scm } } @@ -26,72 +18,25 @@ pipeline { stage('Validate') { steps { script { - echo "Validating repository structure..." sh ''' if [ ! -f "index.html" ]; then echo "Error: index.html not found!" exit 1 fi - - if grep -q "Hello world!" index.html; then - echo "HTML content validation passed" - else - echo "Warning: Expected content not found in index.html" - fi - - echo "Repository validation completed" + echo "Validation passed: index.html exists" ''' } } } - stage('Prepare Dockerfile') { - steps { - script { - echo "Creating Dockerfile..." - writeFile file: 'Dockerfile', - text: ''' - # Use Ubuntu as base image - FROM ubuntu:20.04 - # Prevent interactive prompts - ENV DEBIAN_FRONTEND=noninteractive - # Install Apache - RUN apt-get update && \\ - apt-get install -y apache2 && \\ - apt-get clean && \\ - rm -rf /var/lib/apt/lists/* - - # Copy website files to Apache document root - COPY . /var/www/html/ - - # Set permissions - RUN chown -R www-data:www-data /var/www/html && \\ - chmod -R 755 /var/www/html - - # Expose Apache port - EXPOSE 80 - - # Start Apache in foreground - CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] - ''' - } - } - } - stage('Build Docker Image') { steps { script { - echo "Building Docker image for branch: \${env.BRANCH_NAME}" - - def imageTag = "\${env.BRANCH_NAME}-\${env.BUILD_NUMBER}" - + def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" sh """ - docker build -t \${IMAGE_NAME}:\${imageTag} . - docker build -t \${IMAGE_NAME}:\${env.BRANCH_NAME}-latest . - - echo "Docker image built successfully: \${IMAGE_NAME}:\${imageTag}" + docker build -t ${IMAGE_NAME}:${imageTag} . + docker tag ${IMAGE_NAME}:${imageTag} ${IMAGE_NAME}:${env.BRANCH_NAME}-latest """ - env.IMAGE_TAG = imageTag } } @@ -100,139 +45,45 @@ pipeline { stage('Test Build') { steps { script { - echo "Testing Docker image build..." - sh """ - docker run -d --name test-container-\${BUILD_NUMBER} \ - -p 8080:80 \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 15 - - response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") - - if [ "\\$response" = "200" ]; then - echo "HTTP test passed" - else - echo "HTTP test failed" + docker run -d --name test-container-${BUILD_NUMBER} -p 8080:80 ${IMAGE_NAME}:${env.IMAGE_TAG} + sleep 10 + response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + if [ "\$response" != "200" ]; then + echo "Build test failed" exit 1 fi - - content=\\$(curl -s http://localhost:8080 || echo "") - if echo "\\$content" | grep -q "Hello world!"; then - echo "Content test passed" - else - echo "Content test failed" - exit 1 - fi - - docker stop test-container-\${BUILD_NUMBER} - docker rm test-container-\${BUILD_NUMBER} - - echo "Build test completed successfully" + docker stop test-container-${BUILD_NUMBER} + docker rm test-container-${BUILD_NUMBER} """ } } } - stage('Deploy') { - parallel { - stage('Deploy Development') { - when { - branch 'develop' - } - steps { - script { - echo "Deploying to Development Environment..." - - sh """ - docker stop \${DEV_CONTAINER_NAME} 2>/dev/null || true - docker rm \${DEV_CONTAINER_NAME} 2>/dev/null || true - - docker run -d --name \${DEV_CONTAINER_NAME} \ - -p \${DEV_PORT}:80 \ - \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 10 - curl -f http://localhost:\${DEV_PORT} || exit 1 - - echo "Development deployment test completed" - - docker stop \${DEV_CONTAINER_NAME} - docker rm \${DEV_CONTAINER_NAME} - - echo "Development test container cleaned up" - """ - } - } - } - - stage('Deploy Production') { - when { - branch 'master' - } - steps { - script { - echo "Deploying to Production Environment..." - - sh """ - if docker ps -q -f name=\${PROD_CONTAINER_NAME} > /dev/null 2>&1; then - echo "Backing up current production container..." - backup_name="\${PROD_CONTAINER_NAME}-backup-\\$(date +%Y%m%d-%H%M%S)" - docker stop \${PROD_CONTAINER_NAME} - docker rename \${PROD_CONTAINER_NAME} \\$backup_name - fi - - docker run -d --name \${PROD_CONTAINER_NAME} \ - -p \${PROD_PORT}:80 \ - --restart unless-stopped \ - --label "version=\${env.IMAGE_TAG}" \ - --label "deployed-by=jenkins" \ - \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 15 - - response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:\${PROD_PORT} || echo "000") - - if [ "\\$response" = "200" ]; then - echo "Production deployment successful!" - echo "Website is live at http://localhost:\${PROD_PORT}" - else - echo "Production deployment failed" - exit 1 - fi - """ - } - } + stage('Deploy to Production') { + when { + branch 'master' + } + steps { + script { + sh """ + docker stop ${PROD_CONTAINER_NAME} 2>/dev/null || true + docker rm ${PROD_CONTAINER_NAME} 2>/dev/null || true + docker run -d --name ${PROD_CONTAINER_NAME} -p ${PROD_PORT}:80 --restart unless-stopped ${IMAGE_NAME}:${env.IMAGE_TAG} + """ + echo "Production deployed successfully on port ${PROD_PORT}" } } } } post { - success { - script { - if (env.BRANCH_NAME == 'master') { - echo "SUCCESS: Production deployment completed on port \${env.PROD_PORT}" - } else if (env.BRANCH_NAME == 'develop') { - echo "SUCCESS: Development build completed - Ready for production" - } else { - echo "SUCCESS: Feature branch build completed" - } - } - } - - failure { - echo "FAILURE: Pipeline failed for branch \${env.BRANCH_NAME}" - } - always { - script { - sh ''' - docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true - docker image prune -f || true - echo "Cleanup completed" - ''' - } + sh ''' + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Cleanup completed" + ''' } } -} \ No newline at end of file +} From b621bbb215c5c04d30b74c67f3b7b3c95571f5c8 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 13:32:02 +0530 Subject: [PATCH 06/42] Added 1.txt --- a.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 a.txt diff --git a/a.txt b/a.txt new file mode 100644 index 000000000..7a64717c3 --- /dev/null +++ b/a.txt @@ -0,0 +1 @@ +checking From 0e1cf53b0a90366acfa791543aca6ec359bc687c Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 14:00:45 +0530 Subject: [PATCH 07/42] Updated Jenkinsfile syntax correction --- Jenkinsfile | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 639cf8a66..ee703a73b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -34,8 +34,8 @@ pipeline { script { def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" sh """ - docker build -t ${IMAGE_NAME}:${imageTag} . - docker tag ${IMAGE_NAME}:${imageTag} ${IMAGE_NAME}:${env.BRANCH_NAME}-latest + docker build -t ${env.IMAGE_NAME}:${env.imageTag} . + docker tag ${env.IMAGE_NAME}:${env.imageTag} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest """ env.IMAGE_TAG = imageTag } @@ -46,15 +46,15 @@ pipeline { steps { script { sh """ - docker run -d --name test-container-${BUILD_NUMBER} -p 8080:80 ${IMAGE_NAME}:${env.IMAGE_TAG} + docker run -d --name test-container-${env.BUILD_NUMBER} -p 8080:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" exit 1 fi - docker stop test-container-${BUILD_NUMBER} - docker rm test-container-${BUILD_NUMBER} + docker stop test-container-${env.BUILD_NUMBER} + docker rm test-container-${env.BUILD_NUMBER} """ } } @@ -67,11 +67,11 @@ pipeline { steps { script { sh """ - docker stop ${PROD_CONTAINER_NAME} 2>/dev/null || true - docker rm ${PROD_CONTAINER_NAME} 2>/dev/null || true - docker run -d --name ${PROD_CONTAINER_NAME} -p ${PROD_PORT}:80 --restart unless-stopped ${IMAGE_NAME}:${env.IMAGE_TAG} + docker stop ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker rm ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker run -d --name ${env.PROD_CONTAINER_NAME} -p ${env.PROD_PORT}:80 --restart unless-stopped ${env.IMAGE_NAME}:${env.IMAGE_TAG} """ - echo "Production deployed successfully on port ${PROD_PORT}" + echo "Production deployed successfully on port ${env.PROD_PORT}" } } } From 444e497280abbec3dfd2cdb0f614d8dbd9568a41 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 14:03:02 +0530 Subject: [PATCH 08/42] Added b.txt --- b.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 b.txt diff --git a/b.txt b/b.txt new file mode 100644 index 000000000..21b825352 --- /dev/null +++ b/b.txt @@ -0,0 +1 @@ +checking2 From 08a62eba59170130e9f61a19bd075c5b37611219 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 14:13:58 +0530 Subject: [PATCH 09/42] Update Jenkinsfile updated --- Jenkinsfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index ee703a73b..f54aa5778 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,12 +32,11 @@ pipeline { stage('Build Docker Image') { steps { script { - def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + env.Image_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" sh """ docker build -t ${env.IMAGE_NAME}:${env.imageTag} . docker tag ${env.IMAGE_NAME}:${env.imageTag} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest """ - env.IMAGE_TAG = imageTag } } } From a705f0544e536094e3199e021cc396c156bb07b4 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 14:15:06 +0530 Subject: [PATCH 10/42] Added c.txt --- c.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 c.txt diff --git a/c.txt b/c.txt new file mode 100644 index 000000000..21b825352 --- /dev/null +++ b/c.txt @@ -0,0 +1 @@ +checking2 From 3550bef07dd9c47c51ecac852cec78de2dde087b Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 14:23:35 +0530 Subject: [PATCH 11/42] Update Jenkinsfile updated --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index f54aa5778..f3f4ab21a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,7 +32,8 @@ pipeline { stage('Build Docker Image') { steps { script { - env.Image_TAG = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + env.IMAGE_TAG = imageTag sh """ docker build -t ${env.IMAGE_NAME}:${env.imageTag} . docker tag ${env.IMAGE_NAME}:${env.imageTag} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest From 26ec9cb718f613d55837885fd9300c9e1eff9fe6 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 14:33:22 +0530 Subject: [PATCH 12/42] Update Jenkinsfile UPDATED --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f3f4ab21a..70ad3e1ca 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -35,8 +35,8 @@ pipeline { def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" env.IMAGE_TAG = imageTag sh """ - docker build -t ${env.IMAGE_NAME}:${env.imageTag} . - docker tag ${env.IMAGE_NAME}:${env.imageTag} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest + docker build -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} . + docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest """ } } From 6a44fda68df4fd961643c0793b3b7e1ca56f130f Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 14:40:32 +0530 Subject: [PATCH 13/42] Update Jenkinsfile updated --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 70ad3e1ca..38bd3b28e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -46,7 +46,7 @@ pipeline { steps { script { sh """ - docker run -d --name test-container-${env.BUILD_NUMBER} -p 8080:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then From 31e173ef7a60518b27b238a8be0636f34ac7bac7 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 20:54:02 +0530 Subject: [PATCH 14/42] Updated Jenkinsfile updated for simpler format --- Jenkinsfile | 211 ++++++++-------------------------------------------- 1 file changed, 31 insertions(+), 180 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 8488987f4..38bd3b28e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,21 +4,13 @@ pipeline { environment { IMAGE_NAME = 'website-app' PROD_CONTAINER_NAME = 'website-prod' - DEV_CONTAINER_NAME = 'website-dev' PROD_PORT = '82' - DEV_PORT = '8081' - } - - options { - buildDiscarder(logRotator(numToKeepStr: '10')) - timeout(time: 30, unit: 'MINUTES') - timestamps() } stages { stage('Checkout') { steps { - echo "Checking out code from branch: \${env.BRANCH_NAME}" + echo "Checking out branch: ${env.BRANCH_NAME}" checkout scm } } @@ -26,73 +18,26 @@ pipeline { stage('Validate') { steps { script { - echo "Validating repository structure..." sh ''' if [ ! -f "index.html" ]; then echo "Error: index.html not found!" exit 1 fi - - if grep -q "Hello world!" index.html; then - echo "HTML content validation passed" - else - echo "Warning: Expected content not found in index.html" - fi - - echo "Repository validation completed" + echo "Validation passed: index.html exists" ''' } } } - stage('Prepare Dockerfile') { - steps { - script { - echo "Creating Dockerfile..." - writeFile file: 'Dockerfile', - text: ''' - # Use Ubuntu as base image - FROM ubuntu:20.04 - # Prevent interactive prompts - ENV DEBIAN_FRONTEND=noninteractive - # Install Apache - RUN apt-get update && \\ - apt-get install -y apache2 && \\ - apt-get clean && \\ - rm -rf /var/lib/apt/lists/* - - # Copy website files to Apache document root - COPY . /var/www/html/ - - # Set permissions - RUN chown -R www-data:www-data /var/www/html && \\ - chmod -R 755 /var/www/html - - # Expose Apache port - EXPOSE 80 - - # Start Apache in foreground - CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] - ''' - } - } - } - stage('Build Docker Image') { steps { script { - echo "Building Docker image for branch: \${env.BRANCH_NAME}" - - def imageTag = "\${env.BRANCH_NAME}-\${env.BUILD_NUMBER}" - + def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" + env.IMAGE_TAG = imageTag sh """ - docker build -t \${IMAGE_NAME}:\${imageTag} . - docker build -t \${IMAGE_NAME}:\${env.BRANCH_NAME}-latest . - - echo "Docker image built successfully: \${IMAGE_NAME}:\${imageTag}" + docker build -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} . + docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest """ - - env.IMAGE_TAG = imageTag } } } @@ -100,139 +45,45 @@ pipeline { stage('Test Build') { steps { script { - echo "Testing Docker image build..." - sh """ - docker run -d --name test-container-\${BUILD_NUMBER} \ - -p 8080:80 \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 15 - - response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") - - if [ "\\$response" = "200" ]; then - echo "HTTP test passed" - else - echo "HTTP test failed" + docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + sleep 10 + response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + if [ "\$response" != "200" ]; then + echo "Build test failed" exit 1 fi - - content=\\$(curl -s http://localhost:8080 || echo "") - if echo "\\$content" | grep -q "Hello world!"; then - echo "Content test passed" - else - echo "Content test failed" - exit 1 - fi - - docker stop test-container-\${BUILD_NUMBER} - docker rm test-container-\${BUILD_NUMBER} - - echo "Build test completed successfully" + docker stop test-container-${env.BUILD_NUMBER} + docker rm test-container-${env.BUILD_NUMBER} """ } } } - stage('Deploy') { - parallel { - stage('Deploy Development') { - when { - branch 'develop' - } - steps { - script { - echo "Deploying to Development Environment..." - - sh """ - docker stop \${DEV_CONTAINER_NAME} 2>/dev/null || true - docker rm \${DEV_CONTAINER_NAME} 2>/dev/null || true - - docker run -d --name \${DEV_CONTAINER_NAME} \ - -p \${DEV_PORT}:80 \ - \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 10 - curl -f http://localhost:\${DEV_PORT} || exit 1 - - echo "Development deployment test completed" - - docker stop \${DEV_CONTAINER_NAME} - docker rm \${DEV_CONTAINER_NAME} - - echo "Development test container cleaned up" - """ - } - } - } - - stage('Deploy Production') { - when { - branch 'master' - } - steps { - script { - echo "Deploying to Production Environment..." - - sh """ - if docker ps -q -f name=\${PROD_CONTAINER_NAME} > /dev/null 2>&1; then - echo "Backing up current production container..." - backup_name="\${PROD_CONTAINER_NAME}-backup-\\$(date +%Y%m%d-%H%M%S)" - docker stop \${PROD_CONTAINER_NAME} - docker rename \${PROD_CONTAINER_NAME} \\$backup_name - fi - - docker run -d --name \${PROD_CONTAINER_NAME} \ - -p \${PROD_PORT}:80 \ - --restart unless-stopped \ - --label "version=\${env.IMAGE_TAG}" \ - --label "deployed-by=jenkins" \ - \${IMAGE_NAME}:\${env.IMAGE_TAG} - - sleep 15 - - response=\\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:\${PROD_PORT} || echo "000") - - if [ "\\$response" = "200" ]; then - echo "Production deployment successful!" - echo "Website is live at http://localhost:\${PROD_PORT}" - else - echo "Production deployment failed" - exit 1 - fi - """ - } - } + stage('Deploy to Production') { + when { + branch 'master' + } + steps { + script { + sh """ + docker stop ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker rm ${env.PROD_CONTAINER_NAME} 2>/dev/null || true + docker run -d --name ${env.PROD_CONTAINER_NAME} -p ${env.PROD_PORT}:80 --restart unless-stopped ${env.IMAGE_NAME}:${env.IMAGE_TAG} + """ + echo "Production deployed successfully on port ${env.PROD_PORT}" } } } } post { - success { - script { - if (env.BRANCH_NAME == 'master') { - echo "SUCCESS: Production deployment completed on port \${env.PROD_PORT}" - } else if (env.BRANCH_NAME == 'develop') { - echo "SUCCESS: Development build completed - Ready for production" - } else { - echo "SUCCESS: Feature branch build completed" - } - } - } - - failure { - echo "FAILURE: Pipeline failed for branch \${env.BRANCH_NAME}" - } - always { - script { - sh ''' - docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true - docker image prune -f || true - echo "Cleanup completed" - ''' - } + sh ''' + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Cleanup completed" + ''' } } -} \ No newline at end of file +} From 9488bd286a9c9be7c779b2be8fb33f6ab6f5c0b1 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 20:55:45 +0530 Subject: [PATCH 15/42] Created Dockerfile For CI/CD --- Dockerfile | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..39cc403e9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# Use Ubuntu as base image +FROM ubuntu:20.04 + +# Prevent interactive prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install Apache +RUN apt-get update && \ + apt-get install -y apache2 && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Copy website files to Apache document root +COPY . /var/www/html/ + +# Set permissions +RUN chown -R www-data:www-data /var/www/html && \ + chmod -R 755 /var/www/html + +# Expose Apache port +EXPOSE 80 + +# Start Apache in foreground +CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"] From 014413f92aab41ee11afdd42cef7f4ea3f2c90d1 Mon Sep 17 00:00:00 2001 From: rahul Date: Thu, 28 Aug 2025 21:12:56 +0530 Subject: [PATCH 16/42] Added d.txt --- d.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 d.txt diff --git a/d.txt b/d.txt new file mode 100644 index 000000000..02d182ca5 --- /dev/null +++ b/d.txt @@ -0,0 +1 @@ +checking3 From 97d77c94789b07973dcdd5016e33da95ce61ebc9 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 22:00:25 +0530 Subject: [PATCH 17/42] Update Jenkinsfile added some comments --- Jenkinsfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 38bd3b28e..16ed908fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,6 +18,7 @@ pipeline { stage('Validate') { steps { script { + echo "Validating repository structure..." sh ''' if [ ! -f "index.html" ]; then echo "Error: index.html not found!" @@ -32,11 +33,13 @@ pipeline { stage('Build Docker Image') { steps { script { + echo "Building Docker image for branch: ${env.BRANCH_NAME}" def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" env.IMAGE_TAG = imageTag sh """ docker build -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} . docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest + echo "DOCKER IMAGE BUILT SUCCESSFULLY: ${env.IMAGE_NAME}:${env.IMAGE_TAG}" """ } } @@ -45,16 +48,20 @@ pipeline { stage('Test Build') { steps { script { + echo "Testing Docker image build..." sh """ docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" + else + echo "Build test passed" exit 1 fi docker stop test-container-${env.BUILD_NUMBER} docker rm test-container-${env.BUILD_NUMBER} + echo "Build test completed successfully" """ } } From 234bf2b5235e920a7d6cdf1a6be136e718eb7aa0 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 22:01:21 +0530 Subject: [PATCH 18/42] Update Jenkinsfile added some comments --- Jenkinsfile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 38bd3b28e..16ed908fe 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,6 +18,7 @@ pipeline { stage('Validate') { steps { script { + echo "Validating repository structure..." sh ''' if [ ! -f "index.html" ]; then echo "Error: index.html not found!" @@ -32,11 +33,13 @@ pipeline { stage('Build Docker Image') { steps { script { + echo "Building Docker image for branch: ${env.BRANCH_NAME}" def imageTag = "${env.BRANCH_NAME}-${env.BUILD_NUMBER}" env.IMAGE_TAG = imageTag sh """ docker build -t ${env.IMAGE_NAME}:${env.IMAGE_TAG} . docker tag ${env.IMAGE_NAME}:${env.IMAGE_TAG} ${env.IMAGE_NAME}:${env.BRANCH_NAME}-latest + echo "DOCKER IMAGE BUILT SUCCESSFULLY: ${env.IMAGE_NAME}:${env.IMAGE_TAG}" """ } } @@ -45,16 +48,20 @@ pipeline { stage('Test Build') { steps { script { + echo "Testing Docker image build..." sh """ docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" + else + echo "Build test passed" exit 1 fi docker stop test-container-${env.BUILD_NUMBER} docker rm test-container-${env.BUILD_NUMBER} + echo "Build test completed successfully" """ } } From f69a02adacb7e61650141c54672b39af3aa19506 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 22:35:25 +0530 Subject: [PATCH 19/42] Update Jenkinsfile updated --- Jenkinsfile | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 16ed908fe..4cb3fead7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,8 +49,15 @@ pipeline { steps { script { echo "Testing Docker image build..." + + def testContainer = "test-container" + sh """ - docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + # stop and remove any leftover test container + docker rm -f ${testContainer} 2>/dev/bull || true + + # Run new test container on port 8081 + docker run -d --name testContainer -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then @@ -59,8 +66,8 @@ pipeline { echo "Build test passed" exit 1 fi - docker stop test-container-${env.BUILD_NUMBER} - docker rm test-container-${env.BUILD_NUMBER} + docker stop test-Container + docker rm -f test-Container echo "Build test completed successfully" """ } From f944048ff4507109fdc66011a9ca6343a718c5e7 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 22:48:33 +0530 Subject: [PATCH 20/42] Update Jenkinsfile updated --- Jenkinsfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4cb3fead7..02cf20a48 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,12 +59,12 @@ pipeline { # Run new test container on port 8081 docker run -d --name testContainer -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 - response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" + exit 1 else echo "Build test passed" - exit 1 fi docker stop test-Container docker rm -f test-Container From ff1ec7ea7fe418c998479ff3ae1930090a8fab7b Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 22:59:38 +0530 Subject: [PATCH 21/42] Update Jenkinsfile Updated --- Jenkinsfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 02cf20a48..24dad6d21 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -54,10 +54,10 @@ pipeline { sh """ # stop and remove any leftover test container - docker rm -f ${testContainer} 2>/dev/bull || true + docker rm -f ${testContainer} 2>/dev/null || true # Run new test container on port 8081 - docker run -d --name testContainer -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + docker run -d --name ${testContainer} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 10 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") if [ "\$response" != "200" ]; then @@ -66,8 +66,8 @@ pipeline { else echo "Build test passed" fi - docker stop test-Container - docker rm -f test-Container + docker stop ${testContainer} + docker rm -f ${testContainer} echo "Build test completed successfully" """ } From ec2571e5e02a029d3a71d4669b7ad36cb05b8af9 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 23:15:44 +0530 Subject: [PATCH 22/42] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 24dad6d21..ef5d8cc77 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -58,7 +58,7 @@ pipeline { # Run new test container on port 8081 docker run -d --name ${testContainer} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} - sleep 10 + sleep 20 response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" From 1d1956d657f77c4842b2819ea66f258a0afbbca3 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 23:27:52 +0530 Subject: [PATCH 23/42] Update Jenkinsfile updated --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index ef5d8cc77..22c7e104e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,7 +59,7 @@ pipeline { # Run new test container on port 8081 docker run -d --name ${testContainer} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 20 - response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") + response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" exit 1 From 30bbd4052160e2e5ee497fa749d25aaf62387805 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Thu, 28 Aug 2025 23:28:50 +0530 Subject: [PATCH 24/42] Update Jenkinsfile . --- Jenkinsfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 22c7e104e..c826706b4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,8 +66,6 @@ pipeline { else echo "Build test passed" fi - docker stop ${testContainer} - docker rm -f ${testContainer} echo "Build test completed successfully" """ } From 16277f3906b1f7cf3d6afcb0d7128072492215e5 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 00:02:18 +0530 Subject: [PATCH 25/42] Update Jenkinsfile skipping clean up for debugging --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index c826706b4..a7969f2bf 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -92,9 +92,9 @@ pipeline { post { always { sh ''' - docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true - docker image prune -f || true - echo "Cleanup completed" + # docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + # docker image prune -f || true + echo "Skipping cleanup for debugging" ''' } } From 06e58e9966249fb050aed642e3eded5ae5f974e5 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 07:32:39 +0530 Subject: [PATCH 26/42] Update Jenkinsfile . --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a7969f2bf..9f30affe1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -59,7 +59,7 @@ pipeline { # Run new test container on port 8081 docker run -d --name ${testContainer} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 20 - response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" exit 1 @@ -92,8 +92,8 @@ pipeline { post { always { sh ''' - # docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true - # docker image prune -f || true + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true echo "Skipping cleanup for debugging" ''' } From 4b6a378b2f7b4174f8f7ed6f678bfeb503664d07 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 10:26:21 +0530 Subject: [PATCH 27/42] Update Jenkinsfile Added Docker network --- Jenkinsfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 9f30affe1..409160cf3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -51,15 +51,20 @@ pipeline { echo "Testing Docker image build..." def testContainer = "test-container" + def networkName = "jenkins-test-network" sh """ + # Create network if it doesn't exist + docker network create ${networkName} 2>/dev/null || true + # stop and remove any leftover test container docker rm -f ${testContainer} 2>/dev/null || true # Run new test container on port 8081 - docker run -d --name ${testContainer} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + docker run -d --name ${testContainer} --network ${networkName} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} sleep 20 - response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8081 || echo "000") + + response=\$(docker run --rm --network ${networkName} curlimages/curl -s -o /dev/null -w "%{http_code}" http://${testContainer}:80 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" exit 1 From b53b1f2f19112ed43296065e59fce07f6c6b6b50 Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 12:56:44 +0530 Subject: [PATCH 28/42] Deleted d.txt --- d.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 d.txt diff --git a/d.txt b/d.txt deleted file mode 100644 index 02d182ca5..000000000 --- a/d.txt +++ /dev/null @@ -1 +0,0 @@ -checking3 From 1ab3c4dec095111c7e9382debdec67fb938b63f6 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 13:53:41 +0530 Subject: [PATCH 29/42] Update Jenkinsfile updated webhook token --- Jenkinsfile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 409160cf3..6c102a5e9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,6 +1,23 @@ pipeline { agent any + properties([ + pipelineTriggers([ + [ + $class: 'GenericTrigger', + genericVariables: [ + [key: 'ref', value: '$.ref'], + [key: 'pusher', value: '$.pusher.name'] + ], + causeString: 'Triggered by GitHub push from $pusher on $ref', + token: 'rahul-webhook-token', + printContributedVariables: true, + printPostContent: true, + regexpFilterText: '$ref', + regexpFilterExpression: 'refs/heads/.*' + ] + ]) +]) environment { IMAGE_NAME = 'website-app' PROD_CONTAINER_NAME = 'website-prod' From 28688fafc666d2b00171e3f4f2af443accc7c21f Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 13:58:07 +0530 Subject: [PATCH 30/42] checking4 --- d.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 d.txt diff --git a/d.txt b/d.txt new file mode 100644 index 000000000..5be8c04ed --- /dev/null +++ b/d.txt @@ -0,0 +1 @@ +checking4 From dff73d2b19e87c60cccd42632212c004eedcbe2c Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 14:08:22 +0530 Subject: [PATCH 31/42] Update Jenkinsfile updated --- Jenkinsfile | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6c102a5e9..0f7b1fe93 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,23 +1,27 @@ pipeline { agent any - properties([ - pipelineTriggers([ - [ - $class: 'GenericTrigger', + triggers { + // Generic Webhook Trigger must go here, not in properties() + GenericTrigger( genericVariables: [ - [key: 'ref', value: '$.ref'], - [key: 'pusher', value: '$.pusher.name'] + [key: 'ref', value: '$.ref'], + [key: 'pusher', value: '$.pusher.name'] ], - causeString: 'Triggered by GitHub push from $pusher on $ref', - token: 'rahul-webhook-token', + causeString: 'Triggered by $pusher on $ref', + token: 'your-webhook-token', printContributedVariables: true, - printPostContent: true, - regexpFilterText: '$ref', - regexpFilterExpression: 'refs/heads/.*' - ] - ]) -]) + printPostContent: true, + regexpFilterText: '$ref', + regexpFilterExpression: 'refs/heads/.*' + ) + } + stages { + stage('Build Info') { + steps { + echo "Triggered by ${pusher} on ${ref}" + } + } environment { IMAGE_NAME = 'website-app' PROD_CONTAINER_NAME = 'website-prod' From d1688efac977626cf08465dcc9941141e2dbef51 Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 14:09:51 +0530 Subject: [PATCH 32/42] deleted d.txt --- d.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 d.txt diff --git a/d.txt b/d.txt deleted file mode 100644 index 5be8c04ed..000000000 --- a/d.txt +++ /dev/null @@ -1 +0,0 @@ -checking4 From 422bc623043f108fc41107a1a9f4cea5940cb918 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 14:18:17 +0530 Subject: [PATCH 33/42] Update Jenkinsfile updated --- Jenkinsfile | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0f7b1fe93..f481eda74 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,17 +16,19 @@ pipeline { regexpFilterExpression: 'refs/heads/.*' ) } + + environment { + IMAGE_NAME = 'website-app' + PROD_CONTAINER_NAME = 'website-prod' + PROD_PORT = '82' + } stages { stage('Build Info') { steps { echo "Triggered by ${pusher} on ${ref}" } } - environment { - IMAGE_NAME = 'website-app' - PROD_CONTAINER_NAME = 'website-prod' - PROD_PORT = '82' - } + } stages { stage('Checkout') { From 0188688804c9d9619b8cacf8dbbb04c46f4d5b44 Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 14:20:19 +0530 Subject: [PATCH 34/42] deleted c.txt --- c.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 c.txt diff --git a/c.txt b/c.txt deleted file mode 100644 index 21b825352..000000000 --- a/c.txt +++ /dev/null @@ -1 +0,0 @@ -checking2 From f8efc0ee463f36b63aaf9c46dcd25037f9a86c8a Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 14:23:43 +0530 Subject: [PATCH 35/42] Update Jenkinsfile updated --- Jenkinsfile | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f481eda74..3dba7e820 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -22,15 +22,11 @@ pipeline { PROD_CONTAINER_NAME = 'website-prod' PROD_PORT = '82' } - stages { - stage('Build Info') { + stages { + stage('Build Info') { steps { echo "Triggered by ${pusher} on ${ref}" - } - } - } - - stages { + } stage('Checkout') { steps { echo "Checking out branch: ${env.BRANCH_NAME}" From a99ca0011fd21ce10449a468e3565dafdb1ddf9d Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 14:42:34 +0530 Subject: [PATCH 36/42] Update Jenkinsfile -- --- Jenkinsfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3dba7e820..2ce0a868b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -26,7 +26,8 @@ pipeline { stage('Build Info') { steps { echo "Triggered by ${pusher} on ${ref}" - } + } + } stage('Checkout') { steps { echo "Checking out branch: ${env.BRANCH_NAME}" From fa34a8d66402a9c20d280b8bc140e8ad0554a92e Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 14:46:13 +0530 Subject: [PATCH 37/42] deleted b.txt --- b.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 b.txt diff --git a/b.txt b/b.txt deleted file mode 100644 index 21b825352..000000000 --- a/b.txt +++ /dev/null @@ -1 +0,0 @@ -checking2 From 0ddd973433c50101b32716cdbb6ce77b4627b20b Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 19:40:13 +0530 Subject: [PATCH 38/42] Update Jenkinsfile - --- Jenkinsfile | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2ce0a868b..c26b299b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,21 +1,5 @@ pipeline { agent any - - triggers { - // Generic Webhook Trigger must go here, not in properties() - GenericTrigger( - genericVariables: [ - [key: 'ref', value: '$.ref'], - [key: 'pusher', value: '$.pusher.name'] - ], - causeString: 'Triggered by $pusher on $ref', - token: 'your-webhook-token', - printContributedVariables: true, - printPostContent: true, - regexpFilterText: '$ref', - regexpFilterExpression: 'refs/heads/.*' - ) - } environment { IMAGE_NAME = 'website-app' @@ -23,11 +7,6 @@ pipeline { PROD_PORT = '82' } stages { - stage('Build Info') { - steps { - echo "Triggered by ${pusher} on ${ref}" - } - } stage('Checkout') { steps { echo "Checking out branch: ${env.BRANCH_NAME}" From 961e796b7be2c779d3aa290074235e6929d758ae Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 19:56:10 +0530 Subject: [PATCH 39/42] Update Jenkinsfile Updated --- Jenkinsfile | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 16ed908fe..c26b299b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,13 +1,12 @@ pipeline { agent any - + environment { IMAGE_NAME = 'website-app' PROD_CONTAINER_NAME = 'website-prod' PROD_PORT = '82' } - - stages { + stages { stage('Checkout') { steps { echo "Checking out branch: ${env.BRANCH_NAME}" @@ -49,18 +48,28 @@ pipeline { steps { script { echo "Testing Docker image build..." + + def testContainer = "test-container" + def networkName = "jenkins-test-network" + sh """ - docker run -d --name test-container-${env.BUILD_NUMBER} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} - sleep 10 - response=\$(curl -s -o /dev/null -w "%{http_code}" http://localhost:8080 || echo "000") + # Create network if it doesn't exist + docker network create ${networkName} 2>/dev/null || true + + # stop and remove any leftover test container + docker rm -f ${testContainer} 2>/dev/null || true + + # Run new test container on port 8081 + docker run -d --name ${testContainer} --network ${networkName} -p 8081:80 ${env.IMAGE_NAME}:${env.IMAGE_TAG} + sleep 20 + + response=\$(docker run --rm --network ${networkName} curlimages/curl -s -o /dev/null -w "%{http_code}" http://${testContainer}:80 || echo "000") if [ "\$response" != "200" ]; then echo "Build test failed" + exit 1 else echo "Build test passed" - exit 1 fi - docker stop test-container-${env.BUILD_NUMBER} - docker rm test-container-${env.BUILD_NUMBER} echo "Build test completed successfully" """ } @@ -87,9 +96,9 @@ pipeline { post { always { sh ''' - docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true - docker image prune -f || true - echo "Cleanup completed" + docker ps -aq --filter "name=test-container" | xargs -r docker rm -f || true + docker image prune -f || true + echo "Skipping cleanup for debugging" ''' } } From 49183612b62482db968e69e7a288bdf406e9db2b Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 22:35:04 +0530 Subject: [PATCH 40/42] added b.txt --- b.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 b.txt diff --git a/b.txt b/b.txt new file mode 100644 index 000000000..5bcdddfaf --- /dev/null +++ b/b.txt @@ -0,0 +1 @@ +checking5 From 25a9f24d19376d29fc5a45ebe67593b2c7a9c8d1 Mon Sep 17 00:00:00 2001 From: rahulmg07 Date: Fri, 29 Aug 2025 22:40:28 +0530 Subject: [PATCH 41/42] Update Jenkinsfile ... --- Jenkinsfile | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 43e0e0e31..c26b299b9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,27 +1,5 @@ pipeline { agent any -<<<<<<< HEAD -<<<<<<< HEAD - - triggers { - // Generic Webhook Trigger must go here, not in properties() - GenericTrigger( - genericVariables: [ - [key: 'ref', value: '$.ref'], - [key: 'pusher', value: '$.pusher.name'] - ], - causeString: 'Triggered by $pusher on $ref', - token: 'your-webhook-token', - printContributedVariables: true, - printPostContent: true, - regexpFilterText: '$ref', - regexpFilterExpression: 'refs/heads/.*' - ) - } -======= ->>>>>>> 961e796b7be2c779d3aa290074235e6929d758ae -======= ->>>>>>> 0ddd973433c50101b32716cdbb6ce77b4627b20b environment { IMAGE_NAME = 'website-app' @@ -29,17 +7,6 @@ pipeline { PROD_PORT = '82' } stages { -<<<<<<< HEAD -<<<<<<< HEAD - stage('Build Info') { - steps { - echo "Triggered by ${pusher} on ${ref}" - } - } -======= ->>>>>>> 961e796b7be2c779d3aa290074235e6929d758ae -======= ->>>>>>> 0ddd973433c50101b32716cdbb6ce77b4627b20b stage('Checkout') { steps { echo "Checking out branch: ${env.BRANCH_NAME}" From 0d73638301aa8a3996c787b87dd65ba353c25317 Mon Sep 17 00:00:00 2001 From: rahul Date: Fri, 29 Aug 2025 22:45:16 +0530 Subject: [PATCH 42/42] added feature2.txt --- feature2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 feature2.txt diff --git a/feature2.txt b/feature2.txt new file mode 100644 index 000000000..397ef0bf3 --- /dev/null +++ b/feature2.txt @@ -0,0 +1 @@ +checking8494