Skip to content

Commit 1f17856

Browse files
ArneLimburgnilshartmann96
authored andcommitted
feat: Add Jenkins pipeline
1 parent ca9f084 commit 1f17856

File tree

8 files changed

+168
-57
lines changed

8 files changed

+168
-57
lines changed

address-validation-service/Jenkinsfile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
pipeline {
33
agent any
44

5+
parameters {
6+
booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer')
7+
}
8+
59
options {
610
disableConcurrentBuilds()
711
}
@@ -12,6 +16,7 @@ pipeline {
1216
PERFORM_RELEASE = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') && env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ')}"
1317
RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}"
1418
VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}"
19+
ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}"
1520
}
1621

1722
triggers {
@@ -26,16 +31,29 @@ pipeline {
2631
branch 'main'
2732
}
2833
environment name: 'PERFORM_RELEASE', value: 'true'
34+
expression {
35+
params.verifyPacts == true
36+
}
2937
}
3038
}
3139
steps {
3240
echo "Building version ${env.VERSION}"
3341
script {
34-
if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) {
42+
if (params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT")) {
43+
int previousRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) - 1
44+
if (previousRevision >= 0) {
45+
previousVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + previousRevision
46+
sh "mvn scm:checkout -DscmVersionType=tag -DscmVersion=${previousVersion}"
47+
echo "Testing against version ${previousVersion}"
48+
}
49+
} else if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) {
3550
sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B"
3651
}
3752
}
38-
sh 'mvn clean test-compile -B'
53+
sh """
54+
cd ${ROOT_DIRECTORY}
55+
mvn clean test-compile -B
56+
"""
3957
}
4058
}
4159
stage ('Test') {
@@ -45,10 +63,16 @@ pipeline {
4563
branch 'main'
4664
}
4765
environment name: 'PERFORM_RELEASE', value: 'true'
66+
expression {
67+
params.verifyPacts == true
68+
}
4869
}
4970
}
5071
steps {
51-
sh "mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B"
72+
sh """
73+
cd ${ROOT_DIRECTORY}
74+
mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B
75+
"""
5276
}
5377
}
5478
stage ('Package') {
@@ -59,6 +83,9 @@ pipeline {
5983
}
6084
environment name: 'PERFORM_RELEASE', value: 'true'
6185
}
86+
expression {
87+
params.verifyPacts == false
88+
}
6289
}
6390
steps {
6491
sh 'mvn package meecrowave:bundle -Dservice.name=address-validation-service -DskipTests -B'
@@ -72,6 +99,9 @@ pipeline {
7299
}
73100
environment name: 'PERFORM_RELEASE', value: 'true'
74101
}
102+
expression {
103+
params.verifyPacts == false
104+
}
75105
}
76106
steps {
77107
script {
@@ -98,6 +128,9 @@ pipeline {
98128
}
99129
stage ('Deploy') {
100130
when {
131+
expression {
132+
params.verifyPacts == false
133+
}
101134
anyOf {
102135
not {
103136
branch 'main'

address-validation-service/pom.xml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<maven.compiler.target>17</maven.compiler.target>
2020
<failOnMissingWebXml>false</failOnMissingWebXml>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22+
<pactBroker.url>http://localhost:5050</pactBroker.url>
2223
<meecrowave.version>2.0.0</meecrowave.version>
2324
<deltaspike.version>1.9.6</deltaspike.version>
2425
<junit.version>5.8.2</junit.version>
@@ -100,11 +101,6 @@
100101
<version>3.22.0</version>
101102
<scope>test</scope>
102103
</dependency>
103-
<dependency>
104-
<groupId>org.mockito</groupId>
105-
<artifactId>mockito-core</artifactId>
106-
<version>2.28.2</version>
107-
</dependency>
108104
<dependency>
109105
<groupId>au.com.dius.pact.provider</groupId>
110106
<artifactId>junit5</artifactId>
@@ -131,7 +127,6 @@
131127
</dependency>
132128
</dependencies>
133129
<build>
134-
<finalName>${project.artifactId}</finalName>
135130
<plugins>
136131
<plugin>
137132
<groupId>org.apache.maven.plugins</groupId>
@@ -140,6 +135,7 @@
140135
<configuration>
141136
<systemPropertyVariables>
142137
<pact.provider.version>${project.version}</pact.provider.version>
138+
<pactBroker.url>${pactBroker.url}</pactBroker.url>
143139
</systemPropertyVariables>
144140
</configuration>
145141
</plugin>
@@ -152,24 +148,8 @@
152148
<artifactId>maven-checkstyle-plugin</artifactId>
153149
<version>3.2.1</version>
154150
<configuration>
155-
<consoleOutput>true</consoleOutput>
156-
<headerLocation>${project.basedir}/src/main/checkstyle/java.header</headerLocation>
157-
<failsOnError>true</failsOnError>
158-
<consoleOutput>true</consoleOutput>
151+
<conf>${project.basedir}/src/main/meecrowave/conf</conf>
159152
</configuration>
160-
<executions>
161-
<execution>
162-
<id>compile</id>
163-
<phase>compile</phase>
164-
<goals>
165-
<goal>checkstyle</goal>
166-
</goals>
167-
<configuration>
168-
<configLocation>${project.basedir}/src/main/checkstyle/configuration.xml</configLocation>
169-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
170-
</configuration>
171-
</execution>
172-
</executions>
173153
</plugin>
174154
</plugins>
175155
</build>

billing-service/Jenkinsfile

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
pipeline {
33
agent any
44

5+
parameters {
6+
booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer')
7+
}
8+
59
options {
610
disableConcurrentBuilds()
711
}
@@ -12,6 +16,7 @@ pipeline {
1216
PERFORM_RELEASE = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') && env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ')}"
1317
RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}"
1418
VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}"
19+
ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}"
1520
}
1621

1722
triggers {
@@ -26,16 +31,29 @@ pipeline {
2631
branch 'main'
2732
}
2833
environment name: 'PERFORM_RELEASE', value: 'true'
34+
expression {
35+
params.verifyPacts == true
36+
}
2937
}
3038
}
3139
steps {
3240
echo "Building version ${env.VERSION}"
3341
script {
34-
if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) {
42+
if (params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT")) {
43+
int previousRevision = Integer.parseInt(env.RELEASE_VERSION.substring(env.RELEASE_VERSION.lastIndexOf(".") + 1)) - 1
44+
if (previousRevision >= 0) {
45+
previousVersion = RELEASE_VERSION.substring(0, env.RELEASE_VERSION.lastIndexOf(".")) + "." + previousRevision
46+
sh "mvn scm:checkout -DscmVersionType=tag -DscmVersion=${previousVersion}"
47+
echo "Testing against version ${previousVersion}"
48+
}
49+
} else if (env.PERFORM_RELEASE.equals('true') && !env.RELEASE_VERSION.equals(env.SNAPSHOT_VERSION)) {
3550
sh "mvn versions:set -DnewVersion=${env.RELEASE_VERSION} -B"
3651
}
3752
}
38-
sh 'mvn clean test-compile -B'
53+
sh """
54+
cd ${ROOT_DIRECTORY}
55+
mvn clean test-compile -B
56+
"""
3957
}
4058
}
4159
stage ('Test') {
@@ -45,10 +63,16 @@ pipeline {
4563
branch 'main'
4664
}
4765
environment name: 'PERFORM_RELEASE', value: 'true'
66+
expression {
67+
params.verifyPacts == true
68+
}
4869
}
4970
}
5071
steps {
51-
sh "mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B"
72+
sh """
73+
cd ${ROOT_DIRECTORY}
74+
mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B
75+
"""
5276
}
5377
}
5478
stage ('Package') {
@@ -59,6 +83,9 @@ pipeline {
5983
}
6084
environment name: 'PERFORM_RELEASE', value: 'true'
6185
}
86+
expression {
87+
params.verifyPacts == false
88+
}
6289
}
6390
steps {
6491
sh 'mvn package meecrowave:bundle -Dservice.name=billing-service -DskipTests -B'
@@ -72,6 +99,9 @@ pipeline {
7299
}
73100
environment name: 'PERFORM_RELEASE', value: 'true'
74101
}
102+
expression {
103+
params.verifyPacts == false
104+
}
75105
}
76106
steps {
77107
script {
@@ -98,6 +128,9 @@ pipeline {
98128
}
99129
stage ('Deploy') {
100130
when {
131+
expression {
132+
params.verifyPacts == false
133+
}
101134
anyOf {
102135
not {
103136
branch 'main'

billing-service/pom.xml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<failOnMissingWebXml>false</failOnMissingWebXml>
2121
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2222
<meecrowave.version>2.0.0</meecrowave.version>
23+
<pactBroker.url>http://localhost:5050</pactBroker.url>
2324
<deltaspike.version>1.9.6</deltaspike.version>
2425
<junit.version>5.8.2</junit.version>
2526
</properties>
@@ -100,12 +101,6 @@
100101
<version>3.22.0</version>
101102
<scope>test</scope>
102103
</dependency>
103-
<dependency>
104-
<groupId>org.mockito</groupId>
105-
<artifactId>mockito-core</artifactId>
106-
<version>2.28.2</version>
107-
<scope>test</scope>
108-
</dependency>
109104
<dependency>
110105
<groupId>au.com.dius.pact.provider</groupId>
111106
<artifactId>junit5</artifactId>
@@ -132,7 +127,6 @@
132127
</dependency>
133128
</dependencies>
134129
<build>
135-
<finalName>${project.artifactId}</finalName>
136130
<plugins>
137131
<plugin>
138132
<groupId>org.apache.maven.plugins</groupId>
@@ -141,6 +135,7 @@
141135
<configuration>
142136
<systemPropertyVariables>
143137
<pact.provider.version>${project.version}</pact.provider.version>
138+
<pactBroker.url>${pactBroker.url}</pactBroker.url>
144139
</systemPropertyVariables>
145140
</configuration>
146141
</plugin>
@@ -153,24 +148,8 @@
153148
<artifactId>maven-checkstyle-plugin</artifactId>
154149
<version>3.2.1</version>
155150
<configuration>
156-
<consoleOutput>true</consoleOutput>
157-
<headerLocation>${project.basedir}/src/main/checkstyle/java.header</headerLocation>
158-
<failsOnError>true</failsOnError>
159-
<consoleOutput>true</consoleOutput>
151+
<conf>${project.basedir}/src/main/meecrowave/conf</conf>
160152
</configuration>
161-
<executions>
162-
<execution>
163-
<id>compile</id>
164-
<phase>compile</phase>
165-
<goals>
166-
<goal>checkstyle</goal>
167-
</goals>
168-
<configuration>
169-
<configLocation>${project.basedir}/src/main/checkstyle/configuration.xml</configLocation>
170-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
171-
</configuration>
172-
</execution>
173-
</executions>
174153
</plugin>
175154
</plugins>
176155
</build>

customer-service/Jenkinsfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,27 @@ pipeline {
4848
}
4949
}
5050
steps {
51-
sh 'mvn test pact:publish -DpactBroker.url=http://pact:9292 -B'
51+
sh 'mvn test pact:publish -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B'
52+
}
53+
}
54+
stage ('Test providers') {
55+
when {
56+
anyOf {
57+
not {
58+
branch 'main'
59+
}
60+
environment name: 'PERFORM_RELEASE', value: 'true'
61+
}
62+
}
63+
steps {
64+
parallel(
65+
'delivery-service': {
66+
build job: "delivery-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
67+
},
68+
'billing-service': {
69+
build job: "billing-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
70+
}
71+
)
5272
}
5373
}
5474
stage ('Package') {

customer-service/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@
211211
<pactBrokerUrl>${pactBroker.url}</pactBrokerUrl>
212212
</configuration>
213213
</plugin>
214+
<plugin>
215+
<groupId>org.apache.meecrowave</groupId>
216+
<artifactId>meecrowave-maven-plugin</artifactId>
217+
<version>${meecrowave.version}</version>
218+
<configuration>
219+
<conf>${project.basedir}/src/main/meecrowave/conf</conf>
220+
</configuration>
221+
</plugin>
214222
</plugins>
215223
</build>
216224
</project>

0 commit comments

Comments
 (0)