Skip to content

Commit aa0cf6b

Browse files
authored
Merge pull request #7 from DefinitelyNotTzeJing/branch1
Update master with branch1
2 parents 1caf6dd + 0a0c1af commit aa0cf6b

9 files changed

Lines changed: 137 additions & 58 deletions

File tree

.github/workflows/build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches:
6+
- branch1
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
22+
- name: Build with Maven
23+
run: mvn package

.github/workflows/deploy.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- branch1
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: '17'
21+
22+
- name: Build with Maven
23+
run: mvn package
24+
25+
- name: Set up Docker
26+
uses: docker/setup-buildx-action@v3
27+
28+
- name: Build Docker image
29+
run: docker build -t my-java-app .
30+
31+
- name: Run Docker container
32+
run: docker run -d -p 8081:8081 my-java-app

.github/workflows/test.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- branch1
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
java-version: '17'
20+
distribution: 'temurin'
21+
22+
- name: Run Tests with Maven
23+
run: mvn test

Jenkinsfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
pipeline {
2+
agent any
3+
stages {
4+
stage('Checkout') {
5+
steps {
6+
git branch: 'branch3', url: 'https://github.com/Vanny253/simple-java-maven-app.git'
7+
}
8+
}
9+
stage('Build') {
10+
steps {
11+
bat 'mvn clean package -DskipTests'
12+
}
13+
}
14+
stage('Test') {
15+
steps {
16+
bat 'mvn test'
17+
}
18+
post {
19+
always {
20+
junit 'target/surefire-reports/*.xml' // This will show test results in Jenkins
21+
}
22+
}
23+
}
24+
stage('Deliver') {
25+
steps {
26+
bat 'jenkins\\scripts\\deliver.bat'
27+
}
28+
}
29+
}
30+
post {
31+
always {
32+
echo 'Cleaning up workspace'
33+
deleteDir() // Clean up the workspace after the build
34+
}
35+
success {
36+
echo 'Build succeeded!!!'
37+
}
38+
failure {
39+
echo 'Build failed!'
40+
}
41+
}
42+
}
43+
44+

jenkins/Jenkinsfile

Lines changed: 0 additions & 28 deletions
This file was deleted.

jenkins/scripts/deliver.bat

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@echo off
2+
REM Install your Maven-built JAR into the local repo
3+
echo Running Maven install into Jenkins's local repository…
4+
mvn jar:jar install:install help:evaluate -Dexpression=project.name
5+
6+
REM Read project name and version from the POM
7+
for /f "delims=" %%N in ('mvn -q -DforceStdout help:evaluate -Dexpression=project.name') do set "NAME=%%N"
8+
for /f "delims=" %%V in ('mvn -q -DforceStdout help:evaluate -Dexpression=project.version') do set "VERSION=%%V"
9+
10+
REM Run the built JAR so you can see its output in the console
11+
echo Launching JAR target\%NAME%-%VERSION%.jar…
12+
java -jar target\%NAME%-%VERSION%.jar

jenkins/scripts/deliver.sh

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/main/java/com/mycompany/app/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class App {
77

8-
private static final String MESSAGE = "Hello from Spark Web Server!!!";
8+
private static final String MESSAGE = "Hello from Spark Web Server!!!Come";
99

1010
public App() {}
1111

src/test/java/com/mycompany/app/AppTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.mycompany.app;
22

3-
import org.junit.jupiter.api.Test;
4-
53
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import org.junit.jupiter.api.Test;
65

76
/**
87
* Unit test for simple App.
@@ -20,6 +19,6 @@ public void testAppConstructor() {
2019
public void testAppMessage()
2120
{
2221
App app = new App();
23-
assertEquals("Hello from Spark Web Server!!!", app.getMessage());
22+
assertEquals("Hello from Spark Web Server!!!Come", app.getMessage());
2423
}
2524
}

0 commit comments

Comments
 (0)