From b514b14486d3a27071b955ea0180f54dfbfbfa9d Mon Sep 17 00:00:00 2001 From: ChanTzeJing Date: Sat, 26 Apr 2025 15:49:37 +0800 Subject: [PATCH 01/12] continuous integration script --- .github/workflows/build.yml | 22 ++++++++++++++++++++++ .github/workflows/deploy.yml | 23 +++++++++++++++++++++++ .github/workflows/test.yml | 22 ++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000000..351e64861a --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build + +on: + push: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + + - name: Build with Maven + run: mvn package diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000000..0b6c9f9a44 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,23 @@ +name: Deploy + +on: + push: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: docker build -t my-java-app . + + - name: Run Docker container + run: docker run -d -p 8081:8081 my-java-app diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000000..eb8102a236 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +name: Test + +on: + push: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + + - name: Run Tests with Maven + run: mvn test From b877eae7467b40f7dadd15ce371f51cdbde821e9 Mon Sep 17 00:00:00 2001 From: ChanTzeJing Date: Sat, 26 Apr 2025 15:56:19 +0800 Subject: [PATCH 02/12] testing --- src/main/java/com/mycompany/app/App.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 03621290a2..a4825614cb 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -15,6 +15,6 @@ public static void main(String[] args) { } public String getMessage() { - return MESSAGE; + return MESSAGE; // For testing purposes } } From 7d1b72efc93f2a855cb5d93d7c5eed2b3770c4cb Mon Sep 17 00:00:00 2001 From: ChanTzeJing Date: Sat, 26 Apr 2025 16:01:12 +0800 Subject: [PATCH 03/12] update CI script --- .github/workflows/build.yml | 2 +- .github/workflows/deploy.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 351e64861a..ae38137f78 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,7 +3,7 @@ name: Build on: push: branches: - - main + - branch1 jobs: build: diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0b6c9f9a44..0c6f3fb149 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,7 @@ name: Deploy on: push: branches: - - main + - branch1 jobs: deploy: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index eb8102a236..7d397eb8dc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,7 +3,7 @@ name: Test on: push: branches: - - main + - branch1 jobs: test: From 383af67cf53033623b905229c794dcd47f378b0c Mon Sep 17 00:00:00 2001 From: ChanTzeJing Date: Sat, 26 Apr 2025 17:20:40 +0800 Subject: [PATCH 04/12] update CI --- .github/workflows/build.yml | 1 + .github/workflows/deploy.yml | 9 +++++++++ .github/workflows/test.yml | 1 + 3 files changed, 11 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ae38137f78..5fe46037df 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,7 @@ jobs: uses: actions/setup-java@v4 with: java-version: '17' + distribution: 'temurin' - name: Build with Maven run: mvn package diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0c6f3fb149..912f5291b1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -13,6 +13,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '17' + + - name: Build with Maven + run: mvn package + - name: Set up Docker uses: docker/setup-buildx-action@v3 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d397eb8dc..6ca9ea86de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,7 @@ jobs: uses: actions/setup-java@v4 with: java-version: '17' + distribution: 'temurin' - name: Run Tests with Maven run: mvn test From 19e1f4b32fed6ba3c6ebbeadf57958a06b7e36d0 Mon Sep 17 00:00:00 2001 From: ChanTzeJing Date: Sun, 27 Apr 2025 15:44:51 +0800 Subject: [PATCH 05/12] update --- src/main/java/com/mycompany/app/App.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index a4825614cb..03621290a2 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -15,6 +15,6 @@ public static void main(String[] args) { } public String getMessage() { - return MESSAGE; // For testing purposes + return MESSAGE; } } From cbfef3322e345dadb3208722939dd09c83af8ad4 Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 16:39:13 +0800 Subject: [PATCH 06/12] Update --- jenkins/Jenkinsfile => Jenkinsfile | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename jenkins/Jenkinsfile => Jenkinsfile (100%) diff --git a/jenkins/Jenkinsfile b/Jenkinsfile similarity index 100% rename from jenkins/Jenkinsfile rename to Jenkinsfile From 5b8ba3314bd44ce883c113e093b8e70e1d222479 Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 16:40:32 +0800 Subject: [PATCH 07/12] Update Jenkinsfile --- Jenkinsfile | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 966859677a..4527f478c0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,28 +1,44 @@ pipeline { agent any - options { - skipStagesAfterUnstable() - } stages { + stage('Checkout') { + steps { + git branch: 'branch3', url: 'https://github.com/Vanny253/simple-java-maven-app.git' + } + } stage('Build') { steps { - sh 'mvn -B -DskipTests clean package' + bat 'mvn clean package -DskipTests' } } stage('Test') { steps { - sh 'mvn test' + bat 'mvn test' } post { always { - junit 'target/surefire-reports/*.xml' + junit 'target/surefire-reports/*.xml' // This will show test results in Jenkins } } } - stage('Deliver') { + stage('Deliver') { steps { - sh './jenkins/scripts/deliver.sh' + bat 'jenkins\\scripts\\deliver.bat' } } } + post { + always { + echo 'Cleaning up workspace' + deleteDir() // Clean up the workspace after the build + } + success { + echo 'Build succeeded!!!' + } + failure { + echo 'Build failed!' + } + } } + + From 050f20a4c7a9a46d28e81ee306bdb88176bd1b34 Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 16:43:04 +0800 Subject: [PATCH 08/12] Update deliver.bat --- jenkins/scripts/deliver.bat | 12 ++++++++++++ jenkins/scripts/deliver.sh | 26 -------------------------- 2 files changed, 12 insertions(+), 26 deletions(-) create mode 100644 jenkins/scripts/deliver.bat delete mode 100755 jenkins/scripts/deliver.sh diff --git a/jenkins/scripts/deliver.bat b/jenkins/scripts/deliver.bat new file mode 100644 index 0000000000..579aba2c4e --- /dev/null +++ b/jenkins/scripts/deliver.bat @@ -0,0 +1,12 @@ +@echo off +REM Install your Maven-built JAR into the local repo +echo Running Maven install into Jenkins's local repository… +mvn jar:jar install:install help:evaluate -Dexpression=project.name + +REM Read project name and version from the POM +for /f "delims=" %%N in ('mvn -q -DforceStdout help:evaluate -Dexpression=project.name') do set "NAME=%%N" +for /f "delims=" %%V in ('mvn -q -DforceStdout help:evaluate -Dexpression=project.version') do set "VERSION=%%V" + +REM Run the built JAR so you can see its output in the console +echo Launching JAR target\%NAME%-%VERSION%.jar… +java -jar target\%NAME%-%VERSION%.jar diff --git a/jenkins/scripts/deliver.sh b/jenkins/scripts/deliver.sh deleted file mode 100755 index 39a0636699..0000000000 --- a/jenkins/scripts/deliver.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env bash - -echo 'The following Maven command installs your Maven-built Java application' -echo 'into the local Maven repository, which will ultimately be stored in' -echo 'Jenkins''s local Maven repository (and the "maven-repository" Docker data' -echo 'volume).' -set -x -mvn jar:jar install:install help:evaluate -Dexpression=project.name -set +x - -echo 'The following command extracts the value of the element' -echo 'within of your Java/Maven project''s "pom.xml" file.' -set -x -NAME=`mvn -q -DforceStdout help:evaluate -Dexpression=project.name` -set +x - -echo 'The following command behaves similarly to the previous one but' -echo 'extracts the value of the element within instead.' -set -x -VERSION=`mvn -q -DforceStdout help:evaluate -Dexpression=project.version` -set +x - -echo 'The following command runs and outputs the execution of your Java' -echo 'application (which Jenkins built using Maven) to the Jenkins UI.' -set -x -java -jar target/${NAME}-${VERSION}.jar From af07d3c3a94100734ff375e706306785fc77c87e Mon Sep 17 00:00:00 2001 From: Alison Date: Sun, 27 Apr 2025 17:10:15 +0800 Subject: [PATCH 09/12] Update remove symbol --- src/main/java/com/mycompany/app/App.java | 2 +- src/test/java/com/mycompany/app/AppTest.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 1e603fc409..03621290a2 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -5,7 +5,7 @@ public class App { - private static final String MESSAGE = "Hello from Spark Web Server!!!"; + private static final String MESSAGE = "Hello from Spark Web Server!"; public App() {} diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java index 885be7c250..be2b9eb53a 100644 --- a/src/test/java/com/mycompany/app/AppTest.java +++ b/src/test/java/com/mycompany/app/AppTest.java @@ -1,8 +1,7 @@ package com.mycompany.app; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; /** * Unit test for simple App. @@ -20,6 +19,6 @@ public void testAppConstructor() { public void testAppMessage() { App app = new App(); - assertEquals("Hello from Spark Web Server!!!", app.getMessage()); + assertEquals("Hello from Spark Web Server!", app.getMessage()); } } From 1ebfd4193cf539218d167a482618f4d111f8ca34 Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 17:32:59 +0800 Subject: [PATCH 10/12] Update my choice --- src/main/java/com/mycompany/app/App.java | 2 +- src/test/java/com/mycompany/app/AppTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 1e603fc409..f5e531e3b6 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -5,7 +5,7 @@ public class App { - private static final String MESSAGE = "Hello from Spark Web Server!!!"; + private static final String MESSAGE = "Hello from Spark Web Server!!! UTAR my choice"; public App() {} diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java index 885be7c250..0c0e2e5393 100644 --- a/src/test/java/com/mycompany/app/AppTest.java +++ b/src/test/java/com/mycompany/app/AppTest.java @@ -20,6 +20,6 @@ public void testAppConstructor() { public void testAppMessage() { App app = new App(); - assertEquals("Hello from Spark Web Server!!!", app.getMessage()); + assertEquals("Hello from Spark Web Server!!! UTAR my choice", app.getMessage()); } } From e14bfc73cc98384e3ba2c919bef94b51a7a75a62 Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 17:35:03 +0800 Subject: [PATCH 11/12] Update my choice --- src/main/java/com/mycompany/app/App.java | 2 +- src/test/java/com/mycompany/app/AppTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 1e603fc409..8dd7515720 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -5,7 +5,7 @@ public class App { - private static final String MESSAGE = "Hello from Spark Web Server!!!"; + private static final String MESSAGE = "Hello from Spark Web Server!!!UTAR my choice"; public App() {} diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java index ef0ff94cfe..320a5980f0 100644 --- a/src/test/java/com/mycompany/app/AppTest.java +++ b/src/test/java/com/mycompany/app/AppTest.java @@ -19,6 +19,6 @@ public void testAppConstructor() { public void testAppMessage() { App app = new App(); - assertEquals("Hello from Spark Web Server!!!", app.getMessage()); + assertEquals("Hello from Spark Web Server!!!UTAR my choice", app.getMessage()); } } From d391ba9f9315b06c43fc3e15e3f0b43ed055ad9e Mon Sep 17 00:00:00 2001 From: Vanny253 Date: Sun, 27 Apr 2025 17:46:07 +0800 Subject: [PATCH 12/12] Update come --- src/main/java/com/mycompany/app/App.java | 2 +- src/test/java/com/mycompany/app/AppTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mycompany/app/App.java b/src/main/java/com/mycompany/app/App.java index 8dd7515720..b6e3c0613e 100644 --- a/src/main/java/com/mycompany/app/App.java +++ b/src/main/java/com/mycompany/app/App.java @@ -5,7 +5,7 @@ public class App { - private static final String MESSAGE = "Hello from Spark Web Server!!!UTAR my choice"; + private static final String MESSAGE = "Hello from Spark Web Server!!!Come"; public App() {} diff --git a/src/test/java/com/mycompany/app/AppTest.java b/src/test/java/com/mycompany/app/AppTest.java index 320a5980f0..79db987259 100644 --- a/src/test/java/com/mycompany/app/AppTest.java +++ b/src/test/java/com/mycompany/app/AppTest.java @@ -19,6 +19,6 @@ public void testAppConstructor() { public void testAppMessage() { App app = new App(); - assertEquals("Hello from Spark Web Server!!!UTAR my choice", app.getMessage()); + assertEquals("Hello from Spark Web Server!!!Come", app.getMessage()); } }