From 2345cf8ed654b84d46200d9f621f6a3c58fc305f Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 13:16:49 -0400 Subject: [PATCH 01/22] Added Dockerfile for containerization --- Dockerfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..25b16c2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Build stage +FROM maven:3.8.6-openjdk-11-slim AS build +WORKDIR /app + +# Copy only the POM first to leverage Docker cache +COPY pom.xml . +# Download dependencies +RUN mvn dependency:go-offline + +# Copy source code +COPY src/ /app/src/ +# Build the application +RUN mvn package -DskipTests + +# Runtime stage +FROM openjdk:11-jre-slim +WORKDIR /app + +# Copy the built WAR file from build stage +COPY --from=build /app/target/JavaWeb3.war /app/JavaWeb3.war + +# Expose port 8080 +EXPOSE 8080 + +# Run the application +ENTRYPOINT ["java", "-jar", "JavaWeb3.war"] From bda659bc0c171255882008452f4f04595375facd Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 15:14:55 -0400 Subject: [PATCH 02/22] Add Jenkinsfile for CI/CD pipeline --- Jenkinsfile | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..0af70b0 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,49 @@ +pipeline { + agent any + + environment { + DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') + DOCKER_IMAGE = 'shebwell/javaweb3-calculator' + VERSION = "${env.BUILD_NUMBER}" + } + + stages { + stage('Checkout') { + steps { + git url: 'https://github.com/shebwell/JavaWeb3.git', + branch: 'master' // + } + } + + stage('Build') { + steps { + sh 'mvn clean package' + } + } + + stage('Build Docker Image') { + steps { + script { + docker.build("${DOCKER_IMAGE}:${VERSION}") + } + } + } + + stage('Push to Docker Hub') { + steps { + script { + docker.withRegistry('https://registry.hub.docker.com', DOCKER_HUB_CREDENTIALS) { + docker.image("${DOCKER_IMAGE}:${VERSION}").push() + docker.image("${DOCKER_IMAGE}:${VERSION}").push('latest') + } + } + } + } + } + + post { + always { + echo 'Pipeline execution completed' + } + } +} From bb994d92f612cf0d8bdaa42e4dfe5bc1c454584d Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 20:28:38 -0400 Subject: [PATCH 03/22] Update Jenkinsfile --- Jenkinsfile | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 0af70b0..66bf15c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -3,15 +3,14 @@ pipeline { environment { DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') - DOCKER_IMAGE = 'shebwell/javaweb3-calculator' - VERSION = "${env.BUILD_NUMBER}" + DOCKER_IMAGE = 'shebwell/javaweb3-calculator' // Updated with your username } stages { stage('Checkout') { steps { git url: 'https://github.com/shebwell/JavaWeb3.git', - branch: 'master' // + branch: 'master' // or 'main' based on your repo } } @@ -24,7 +23,7 @@ pipeline { stage('Build Docker Image') { steps { script { - docker.build("${DOCKER_IMAGE}:${VERSION}") + docker.build("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") } } } @@ -33,17 +32,11 @@ pipeline { steps { script { docker.withRegistry('https://registry.hub.docker.com', DOCKER_HUB_CREDENTIALS) { - docker.image("${DOCKER_IMAGE}:${VERSION}").push() - docker.image("${DOCKER_IMAGE}:${VERSION}").push('latest') + docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push() + docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push('latest') } } } } } - - post { - always { - echo 'Pipeline execution completed' - } - } } From c9a6c2e6f50fce77bdec83b87b0d0a6493c9ccac Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 20:34:02 -0400 Subject: [PATCH 04/22] Update Jenkinsfile --- Jenkinsfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 66bf15c..72199d9 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,9 @@ pipeline { agent any + + tools { + maven 'Maven 3.8.6' // Must match the name you configured + } environment { DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') From 04ba2f1950d386def759a2e79fa771fff276dfd3 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 20:45:31 -0400 Subject: [PATCH 05/22] Update pom.xml --- pom.xml | 57 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 9e1759e..1269c0c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,24 +7,53 @@ 0.0.6 WebAppCal Maven Webapp http://maven.apache.org + + + UTF-8 + 11 + 11 + 11 + + 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 + javax.servlet-api + 4.0.1 + provided + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 11 + 11 + 11 + + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + + + + + + + releases + http://52.204.135.48:8081/nexus/content/repositories/releases + + From af3004339b77e8d69e053d168aa6973ff759c4f2 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 20:48:43 -0400 Subject: [PATCH 06/22] Update Jenkinsfile --- Jenkinsfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 72199d9..c39dcc4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,8 +2,9 @@ pipeline { agent any tools { - maven 'Maven 3.8.6' // Must match the name you configured - } + jdk 'jdk11' // Must match JDK installation name in Jenkins + maven 'maven-3.8.6' +} environment { DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') From 94c5c38d63b8d51eabadcf06d196df82f9ac4eaf Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 21:23:55 -0400 Subject: [PATCH 07/22] Update Jenkinsfile --- Jenkinsfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index c39dcc4..1ca4860 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,6 +7,8 @@ pipeline { } environment { + PATH = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin" + DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') DOCKER_IMAGE = 'shebwell/javaweb3-calculator' // Updated with your username } From ef90bebe41f210ac29a378271be21809377a1740 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 21:55:04 -0400 Subject: [PATCH 08/22] Update Jenkinsfile --- Jenkinsfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Jenkinsfile b/Jenkinsfile index 1ca4860..a3ecdf8 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,6 +24,7 @@ pipeline { stage('Build') { steps { sh 'mvn clean package' + sh 'ls -la target/*.war' } } From 3dd11b4d7d5756f0b0411c812df38a2350a1edff Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:01:02 -0400 Subject: [PATCH 09/22] Update Dockerfile --- Dockerfile | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 25b16c2..b7d43fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,26 +1,38 @@ # Build stage FROM maven:3.8.6-openjdk-11-slim AS build + WORKDIR /app -# Copy only the POM first to leverage Docker cache +# First copy only the POM file to cache dependencies COPY pom.xml . -# Download dependencies -RUN mvn dependency:go-offline -# Copy source code -COPY src/ /app/src/ -# Build the application +# Download dependencies (this layer gets cached unless POM changes) +RUN mvn dependency:go-offline -B + +# Copy all source files +COPY src ./src + +# Build the application (skip tests for faster builds) RUN mvn package -DskipTests -# Runtime stage +# Verify the built WAR file exists and is named correctly +RUN ls -la /app/target/*.war + +# Runtime stage - start with clean, small image FROM openjdk:11-jre-slim + WORKDIR /app -# Copy the built WAR file from build stage -COPY --from=build /app/target/JavaWeb3.war /app/JavaWeb3.war +# Copy the WAR file from build stage +# Using wildcard to handle any WAR filename +COPY --from=build /app/target/*.war /app/application.war -# Expose port 8080 +# Expose port 8080 (the default Tomcat/Spring Boot port) EXPOSE 8080 +# Health check (optional but recommended) +HEALTHCHECK --interval=30s --timeout=3s \ + CMD curl -f http://localhost:8080/JavaWeb3/ || exit 1 + # Run the application -ENTRYPOINT ["java", "-jar", "JavaWeb3.war"] +ENTRYPOINT ["java", "-jar", "application.war"] From d1dee3348e8368c19262993117ec137ea6195cc5 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:13:56 -0400 Subject: [PATCH 10/22] Update Jenkinsfile --- Jenkinsfile | 67 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index a3ecdf8..041ef09 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,50 +1,87 @@ pipeline { agent any - + tools { - jdk 'jdk11' // Must match JDK installation name in Jenkins - maven 'maven-3.8.6' -} + maven 'maven-3.8.6' // Maven installation configured in Jenkins + jdk 'jdk11' // JDK 11 installation configured in Jenkins + } environment { - PATH = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin" - - DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') - DOCKER_IMAGE = 'shebwell/javaweb3-calculator' // Updated with your username + DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') // Jenkins credential ID + DOCKER_IMAGE = 'shebwell/javaweb3-calculator' // Your Docker Hub repository + VERSION = "${env.BUILD_NUMBER}" // Version tag for Docker image + DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' } stages { stage('Checkout') { steps { - git url: 'https://github.com/shebwell/JavaWeb3.git', - branch: 'master' // or 'main' based on your repo + git branch: 'master', // or 'main' based on your repo + url: 'https://github.com/shebwell/JavaWeb3.git' } } - stage('Build') { + stage('Build & Test') { steps { sh 'mvn clean package' - sh 'ls -la target/*.war' + sh 'ls -la target/*.war' // Verify WAR file exists + } + + post { + success { + archiveArtifacts artifacts: 'target/*.war', fingerprint: true + } } } stage('Build Docker Image') { + environment { + PATH = "${env.DOCKER_PATH}" // Ensure Docker is in PATH + } steps { script { - docker.build("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") + // Build with BuildKit support and cache + dockerImage = docker.build( + "${DOCKER_IMAGE}:${VERSION}", + "--build-arg BUILDKIT_INLINE_CACHE=1 ." + ) } } } stage('Push to Docker Hub') { + environment { + PATH = "${env.DOCKER_PATH}" // Ensure Docker is in PATH + } steps { script { docker.withRegistry('https://registry.hub.docker.com', DOCKER_HUB_CREDENTIALS) { - docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push() - docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push('latest') + dockerImage.push() + dockerImage.push('latest') // Also push as latest } } } } + + stage('Deploy (Optional)') { + steps { + echo 'Deployment would happen here' + // Example: sh 'kubectl apply -f k8s-deployment.yaml' + } + } + } + + post { + always { + echo 'Pipeline completed - cleaning up workspace' + cleanWs() // Clean up workspace + } + success { + slackSend color: 'good', message: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}" + } + failure { + slackSend color: 'danger', message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}" + emailext body: 'Check ${BUILD_URL}', subject: 'Pipeline Failed', to: 'team@example.com' + } } } From 13d131aedd4b1b6f17cc1401fd444bc84cac6e7d Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:22:33 -0400 Subject: [PATCH 11/22] Update pom.xml --- pom.xml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 1269c0c..955afd1 100644 --- a/pom.xml +++ b/pom.xml @@ -1,6 +1,9 @@ - + + 4.0.0 + com.web.cal WebAppCal war @@ -10,41 +13,86 @@ UTF-8 + UTF-8 11 11 11 + false + JavaWeb3 + + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + - junit - junit - 4.13.2 + org.junit.jupiter + junit-jupiter-engine + 5.8.2 test + + javax.servlet javax.servlet-api 4.0.1 provided + + + + javax.servlet + jstl + 1.2 + + ${war.finalName} + org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.11.0 - 11 - 11 11 + true + true + + org.apache.maven.plugins maven-war-plugin + 3.4.0 + + ${failOnMissingWebXml} + + + true + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + org.apache.maven.plugins + maven-clean-plugin 3.3.2 From 9d6607ca2b3929260b474e39578b60abc68ffe24 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:31:14 -0400 Subject: [PATCH 12/22] Update Jenkinsfile --- Jenkinsfile | 51 +++++++++++++++------------------------------------ 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 041ef09..3c6f0a5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -2,86 +2,65 @@ pipeline { agent any tools { - maven 'maven-3.8.6' // Maven installation configured in Jenkins - jdk 'jdk11' // JDK 11 installation configured in Jenkins + maven 'maven-3.8.6' + jdk 'jdk11' } environment { - DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') // Jenkins credential ID - DOCKER_IMAGE = 'shebwell/javaweb3-calculator' // Your Docker Hub repository - VERSION = "${env.BUILD_NUMBER}" // Version tag for Docker image + DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') + DOCKER_IMAGE = 'shebwell/javaweb3-calculator' DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' } stages { stage('Checkout') { steps { - git branch: 'master', // or 'main' based on your repo + git branch: 'master', url: 'https://github.com/shebwell/JavaWeb3.git' } } - stage('Build & Test') { + stage('Build') { steps { sh 'mvn clean package' - sh 'ls -la target/*.war' // Verify WAR file exists - } - - post { - success { - archiveArtifacts artifacts: 'target/*.war', fingerprint: true - } + sh 'ls -la target/*.war' } } stage('Build Docker Image') { environment { - PATH = "${env.DOCKER_PATH}" // Ensure Docker is in PATH + PATH = "${env.DOCKER_PATH}" } steps { script { - // Build with BuildKit support and cache - dockerImage = docker.build( - "${DOCKER_IMAGE}:${VERSION}", - "--build-arg BUILDKIT_INLINE_CACHE=1 ." - ) + docker.build("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") } } } stage('Push to Docker Hub') { environment { - PATH = "${env.DOCKER_PATH}" // Ensure Docker is in PATH + PATH = "${env.DOCKER_PATH}" } steps { script { docker.withRegistry('https://registry.hub.docker.com', DOCKER_HUB_CREDENTIALS) { - dockerImage.push() - dockerImage.push('latest') // Also push as latest + docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push() } } } } - - stage('Deploy (Optional)') { - steps { - echo 'Deployment would happen here' - // Example: sh 'kubectl apply -f k8s-deployment.yaml' - } - } } post { always { echo 'Pipeline completed - cleaning up workspace' - cleanWs() // Clean up workspace - } - success { - slackSend color: 'good', message: "SUCCESS: ${env.JOB_NAME} #${env.BUILD_NUMBER}" + cleanWs() } failure { - slackSend color: 'danger', message: "FAILED: ${env.JOB_NAME} #${env.BUILD_NUMBER}" - emailext body: 'Check ${BUILD_URL}', subject: 'Pipeline Failed', to: 'team@example.com' + emailext body: 'Check ${BUILD_URL}', + subject: 'Pipeline Failed', + to: 'team@example.com' } } } From 703703c58c1880bacb8b143ee6b03d20edb4aaf7 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:35:47 -0400 Subject: [PATCH 13/22] Update pom.xml --- pom.xml | 93 ++++++++------------------------------------------------- 1 file changed, 13 insertions(+), 80 deletions(-) diff --git a/pom.xml b/pom.xml index 955afd1..b213145 100644 --- a/pom.xml +++ b/pom.xml @@ -1,38 +1,20 @@ - - - 4.0.0 + + - com.web.cal - WebAppCal - war - 0.0.6 - WebAppCal Maven Webapp - http://maven.apache.org - - - UTF-8 - UTF-8 - 11 - 11 - 11 - false - JavaWeb3 - - - + - org.junit.jupiter - junit-jupiter-api - 5.8.2 + junit + junit + 4.13.2 test + + - org.junit.jupiter - junit-jupiter-engine - 5.8.2 + org.hamcrest + hamcrest-core + 1.3 test @@ -43,65 +25,16 @@ 4.0.1 provided - - - - javax.servlet - jstl - 1.2 - - ${war.finalName} - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - 11 - true - true - - - - - - org.apache.maven.plugins - maven-war-plugin - 3.4.0 - - ${failOnMissingWebXml} - - - true - - - - - - org.apache.maven.plugins maven-surefire-plugin - 3.1.2 - - - - - org.apache.maven.plugins - maven-clean-plugin - 3.3.2 + 2.22.2 + - - - - releases - http://52.204.135.48:8081/nexus/content/repositories/releases - - From bd375e632ce6b9aa3ff7021c979d2ea44b54bcd0 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:44:58 -0400 Subject: [PATCH 14/22] Update pom.xml --- pom.xml | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index b213145..6faaa81 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,23 @@ - - + + + 4.0.0 + com.web.cal + WebAppCal + war + 0.0.6 + WebAppCal Maven Webapp + + + UTF-8 + 11 + 11 + + - + junit junit @@ -29,12 +44,21 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + org.apache.maven.plugins + maven-war-plugin + 3.3.2 + org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 2.22.2 - From 888bbe105fbb046a7c2cf92140989c7aaf7317c3 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:47:37 -0400 Subject: [PATCH 15/22] Update Jenkinsfile --- Jenkinsfile | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 3c6f0a5..af94be7 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,11 +12,19 @@ pipeline { DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' } - stages { - stage('Checkout') { - steps { - git branch: 'master', - url: 'https://github.com/shebwell/JavaWeb3.git' + stage('Checkout') { + steps { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/master']], + extensions: [ + [$class: 'CleanBeforeCheckout'] // Cleans workspace before checkout + ], + userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] + ]) + } +} +Additional Verification: } } @@ -57,10 +65,6 @@ pipeline { echo 'Pipeline completed - cleaning up workspace' cleanWs() } - failure { - emailext body: 'Check ${BUILD_URL}', - subject: 'Pipeline Failed', - to: 'team@example.com' } } } From c6a98dec9f85a882260885831f6043d0a1412146 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:47:59 -0400 Subject: [PATCH 16/22] Update Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index af94be7..82d7cf5 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,6 @@ pipeline { ]) } } -Additional Verification: } } From a990d115bb492acd4902cff986e08cee099cdf1e Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:49:55 -0400 Subject: [PATCH 17/22] Update Jenkinsfile --- Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 82d7cf5..c29051a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,7 @@ pipeline { [$class: 'CleanBeforeCheckout'] // Cleans workspace before checkout ], userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] - ]) + ] } } } From ac706f4d8bd178eac59da312362eabacbc2fb6d6 Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:50:44 -0400 Subject: [PATCH 18/22] Update Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index c29051a..916c4b1 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -21,7 +21,6 @@ pipeline { [$class: 'CleanBeforeCheckout'] // Cleans workspace before checkout ], userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] - ] } } } From 907709d33ba589b01b7b8761f85f39e0f05216da Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 22:51:58 -0400 Subject: [PATCH 19/22] Update Jenkinsfile --- Jenkinsfile | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 916c4b1..181802a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,38 +1,38 @@ pipeline { agent any - + tools { maven 'maven-3.8.6' jdk 'jdk11' } - + environment { DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') DOCKER_IMAGE = 'shebwell/javaweb3-calculator' DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' } - - stage('Checkout') { - steps { - checkout([ - $class: 'GitSCM', - branches: [[name: '*/master']], - extensions: [ - [$class: 'CleanBeforeCheckout'] // Cleans workspace before checkout - ], - userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] - } -} + + stages { + stage('Checkout') { + steps { + checkout([ + $class: 'GitSCM', + branches: [[name: '*/master']], + extensions: [ + [$class: 'CleanBeforeCheckout'] + ], + userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] + ]) } } - + stage('Build') { steps { sh 'mvn clean package' sh 'ls -la target/*.war' } } - + stage('Build Docker Image') { environment { PATH = "${env.DOCKER_PATH}" @@ -43,7 +43,7 @@ pipeline { } } } - + stage('Push to Docker Hub') { environment { PATH = "${env.DOCKER_PATH}" @@ -57,12 +57,11 @@ pipeline { } } } - + post { always { echo 'Pipeline completed - cleaning up workspace' cleanWs() } - } } } From 8de628501813afcd4cdf7ef24cc5013fdef6a13e Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 23:27:00 -0400 Subject: [PATCH 20/22] Update Jenkinsfile --- Jenkinsfile | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 181802a..fa6053a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,14 +44,20 @@ pipeline { } } - stage('Push to Docker Hub') { - environment { - PATH = "${env.DOCKER_PATH}" - } + stage('Push to Docker Hub') { steps { script { - docker.withRegistry('https://registry.hub.docker.com', DOCKER_HUB_CREDENTIALS) { - docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}").push() + withCredentials([usernamePassword( + credentialsId: 'docker-hub-credentials', + usernameVariable: 'DOCKER_USER', + passwordVariable: 'DOCKER_PAT' + )]) { + sh """ + docker login -u $DOCKER_USER -p $DOCKER_PAT + docker push ${DOCKER_IMAGE}:${VERSION} + docker tag ${DOCKER_IMAGE}:${VERSION} ${DOCKER_IMAGE}:latest + docker push ${DOCKER_IMAGE}:latest + """ } } } From 43df7b87124ae433aa146e969ea10695da56490a Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 23:31:09 -0400 Subject: [PATCH 21/22] Update Jenkinsfile --- Jenkinsfile | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index fa6053a..4e2885c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -18,9 +18,7 @@ pipeline { checkout([ $class: 'GitSCM', branches: [[name: '*/master']], - extensions: [ - [$class: 'CleanBeforeCheckout'] - ], + extensions: [[$class: 'CleanBeforeCheckout']], userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] ]) } @@ -44,7 +42,10 @@ pipeline { } } - stage('Push to Docker Hub') { + stage('Push to Docker Hub') { + environment { + PATH = "${env.DOCKER_PATH}" + } steps { script { withCredentials([usernamePassword( @@ -54,8 +55,8 @@ pipeline { )]) { sh """ docker login -u $DOCKER_USER -p $DOCKER_PAT - docker push ${DOCKER_IMAGE}:${VERSION} - docker tag ${DOCKER_IMAGE}:${VERSION} ${DOCKER_IMAGE}:latest + docker push ${DOCKER_IMAGE}:${env.BUILD_NUMBER} + docker tag ${DOCKER_IMAGE}:${env.BUILD_NUMBER} ${DOCKER_IMAGE}:latest docker push ${DOCKER_IMAGE}:latest """ } @@ -66,7 +67,7 @@ pipeline { post { always { - echo 'Pipeline completed - cleaning up workspace' + echo 'Pipeline completed — cleaning up workspace' cleanWs() } } From 60eba2aab59d234cdac812b33b9d08d3b50e66af Mon Sep 17 00:00:00 2001 From: shebwell Date: Mon, 12 May 2025 23:34:42 -0400 Subject: [PATCH 22/22] Update Jenkinsfile --- Jenkinsfile | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4e2885c..8a3d859 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -7,7 +7,7 @@ pipeline { } environment { - DOCKER_HUB_CREDENTIALS = credentials('docker-hub-credentials') + DOCKER_HUB_CREDENTIALS = 'docker-hub-credentials' DOCKER_IMAGE = 'shebwell/javaweb3-calculator' DOCKER_PATH = '/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Docker.app/Contents/Resources/bin' } @@ -18,7 +18,9 @@ pipeline { checkout([ $class: 'GitSCM', branches: [[name: '*/master']], - extensions: [[$class: 'CleanBeforeCheckout']], + extensions: [ + [$class: 'CleanBeforeCheckout'] + ], userRemoteConfigs: [[url: 'https://github.com/shebwell/JavaWeb3.git']] ]) } @@ -48,17 +50,11 @@ pipeline { } steps { script { - withCredentials([usernamePassword( - credentialsId: 'docker-hub-credentials', - usernameVariable: 'DOCKER_USER', - passwordVariable: 'DOCKER_PAT' - )]) { - sh """ - docker login -u $DOCKER_USER -p $DOCKER_PAT - docker push ${DOCKER_IMAGE}:${env.BUILD_NUMBER} - docker tag ${DOCKER_IMAGE}:${env.BUILD_NUMBER} ${DOCKER_IMAGE}:latest - docker push ${DOCKER_IMAGE}:latest - """ + docker.withRegistry('https://index.docker.io/v1/', "${DOCKER_HUB_CREDENTIALS}") { + def appImage = docker.image("${DOCKER_IMAGE}:${env.BUILD_NUMBER}") + appImage.push() + appImage.tag('latest') + docker.image("${DOCKER_IMAGE}:latest").push() } } }