Skip to content

Commit 5184ef3

Browse files
committed
update apps to webhook
1 parent f7e7897 commit 5184ef3

4 files changed

Lines changed: 137 additions & 17 deletions

File tree

address-validation-service/Jenkinsfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ pipeline {
2222

2323
triggers {
2424
pollSCM("* * * * *")
25+
GenericTrigger(
26+
genericRequestVariables: [
27+
[key: 'stage', regexpFilter: ''],
28+
[key: 'verifyPacts', regexpFilter: '']
29+
],
30+
31+
causeString: 'Triggered by web hook',
32+
33+
token: 'address-validation-service',
34+
35+
printContributedVariables: true,
36+
printPostContent: true,
37+
38+
silentResponse: false,
39+
40+
regexpFilterText: '$stage',
41+
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
42+
)
2543
}
2644

2745
stages {
@@ -60,6 +78,9 @@ pipeline {
6078
stage ('Test') {
6179
when {
6280
anyOf {
81+
expression {
82+
params.verifyPacts == true
83+
}
6384
not {
6485
branch 'main'
6586
}
@@ -125,6 +146,7 @@ pipeline {
125146
"""
126147
}
127148
}
149+
sh "curl -H 'Content-Type: application/json' -X PUT http://pact-service:8080/pacticipants/address-validation-service/versions/${env.VERSION}/tags/${env.STAGE}"
128150
}
129151
}
130152
stage ('Deploy') {

billing-service/Jenkinsfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ pipeline {
2222

2323
triggers {
2424
pollSCM("* * * * *")
25+
GenericTrigger(
26+
genericRequestVariables: [
27+
[key: 'stage', regexpFilter: ''],
28+
[key: 'verifyPacts', regexpFilter: '']
29+
],
30+
31+
causeString: 'Triggered by web hook',
32+
33+
token: 'billing-service',
34+
35+
printContributedVariables: true,
36+
printPostContent: true,
37+
38+
silentResponse: false,
39+
40+
regexpFilterText: '$stage',
41+
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
42+
)
2543
}
2644

2745
stages {
@@ -89,7 +107,11 @@ pipeline {
89107
}
90108
}
91109
steps {
110+
<<<<<<< HEAD
92111
sh 'mvn package meecrowave:bundle -Dservice.name=billing-service -DskipTests -B'
112+
=======
113+
sh 'mvn package meecrowave:bundle -Dmaven.test.skip=true -B'
114+
>>>>>>> a601c27... update apps to webhook
93115
}
94116
}
95117
stage ('Push') {

customer-service/Jenkinsfile

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

5+
parameters {
6+
booleanParam(name: 'deployOnly', defaultValue: false, description: 'should this job just run to deploy a version')
7+
string(name: 'deploymentVersion', defaultValue: 'latest', description: 'which version should be deployed')
8+
}
9+
510
options {
611
disableConcurrentBuilds()
712
}
@@ -13,10 +18,30 @@ pipeline {
1318
RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}"
1419
VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}"
1520
STAGE = "${env.BRANCH_NAME == 'main' ? 'prod' : 'test'}"
21+
DEPLOYMENT_VERSION = "${params.deploymentVersion != 'latest' ? params.deploymentVersion : env.VERSION}"
1622
}
1723

1824
triggers {
1925
pollSCM("* * * * *")
26+
GenericTrigger(
27+
genericRequestVariables: [
28+
[key: 'stage', regexpFilter: ''],
29+
[key: 'deployOnly', regexpFilter: ''],
30+
[key: 'deploymentVersion', regexpFilter: '']
31+
],
32+
33+
causeString: 'Triggered by web hook',
34+
35+
token: 'customer-service',
36+
37+
printContributedVariables: true,
38+
printPostContent: true,
39+
40+
silentResponse: false,
41+
42+
regexpFilterText: '$stage',
43+
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
44+
)
2045
}
2146

2247
stages {
@@ -28,6 +53,9 @@ pipeline {
2853
}
2954
environment name: 'PERFORM_RELEASE', value: 'true'
3055
}
56+
expression {
57+
params.deployOnly == false
58+
}
3159
}
3260
steps {
3361
echo "Building version ${env.VERSION}"
@@ -47,29 +75,28 @@ pipeline {
4775
}
4876
environment name: 'PERFORM_RELEASE', value: 'true'
4977
}
78+
expression {
79+
params.deployOnly == false
80+
}
5081
}
5182
steps {
52-
sh 'mvn test pact:publish -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B'
83+
sh 'mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B'
5384
}
5485
}
55-
stage ('Test providers') {
86+
stage ('Upload pacts') {
5687
when {
5788
anyOf {
5889
not {
5990
branch 'main'
6091
}
6192
environment name: 'PERFORM_RELEASE', value: 'true'
6293
}
94+
expression {
95+
params.deployOnly == false
96+
}
6397
}
6498
steps {
65-
parallel(
66-
'delivery-service': {
67-
build job: "delivery-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
68-
},
69-
'billing-service': {
70-
build job: "billing-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
71-
}
72-
)
99+
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.consumer.tags=pending-${env.STAGE} -B"
73100
}
74101
}
75102
stage ('Package') {
@@ -80,6 +107,9 @@ pipeline {
80107
}
81108
environment name: 'PERFORM_RELEASE', value: 'true'
82109
}
110+
expression {
111+
params.deployOnly == false
112+
}
83113
}
84114
steps {
85115
sh 'mvn package meecrowave:bundle -Dservice.name=customer-service -DskipTests -B'
@@ -93,6 +123,9 @@ pipeline {
93123
}
94124
environment name: 'PERFORM_RELEASE', value: 'true'
95125
}
126+
expression {
127+
params.deployOnly == false
128+
}
96129
}
97130
steps {
98131
script {
@@ -119,11 +152,20 @@ pipeline {
119152
}
120153
stage ('Deploy') {
121154
when {
155+
expression {
156+
script {
157+
def deploy = sh script: "pact-broker can-i-deploy --pacticipant customer-service --version ${env.DEPLOYMENT_VERSION} --to ${env.STAGE} --broker-base-url pact-service:8080", returnStatus: true
158+
return deploy == 0
159+
}
160+
}
122161
anyOf {
123162
not {
124163
branch 'main'
125164
}
126165
environment name: 'PERFORM_RELEASE', value: 'true'
166+
expression {
167+
params.deployOnly == true
168+
}
127169
}
128170
}
129171
steps {

delivery-service/Jenkinsfile

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pipeline {
44

55
parameters {
66
booleanParam(name: 'verifyPacts', defaultValue: false, description: 'should this job just run to verify pacts from a consumer')
7+
booleanParam(name: 'deployOnly', defaultValue: false, description: 'should this job just run to deploy a version')
8+
string(name: 'deploymentVersion', defaultValue: 'latest', description: 'which version should be deployed')
79
}
810

911
options {
@@ -18,10 +20,31 @@ pipeline {
1820
VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}"
1921
ROOT_DIRECTORY = "${params.verifyPacts == true && env.BRANCH_NAME == 'main' && env.SNAPSHOT_VERSION.endsWith("-SNAPSHOT") ? 'target/checkout' : '.'}"
2022
STAGE = "${env.BRANCH_NAME == 'main' ? 'prod' : 'test'}"
23+
DEPLOYMENT_VERSION = "${params.deploymentVersion != 'latest' ? params.deploymentVersion : env.VERSION}"
2124
}
2225

2326
triggers {
2427
pollSCM("* * * * *")
28+
GenericTrigger(
29+
genericRequestVariables: [
30+
[key: 'stage', regexpFilter: ''],
31+
[key: 'verifyPacts', regexpFilter: ''],
32+
[key: 'deployOnly', regexpFilter: ''],
33+
[key: 'deploymentVersion', regexpFilter: '']
34+
],
35+
36+
causeString: 'Triggered by web hook',
37+
38+
token: 'delivery-service',
39+
40+
printContributedVariables: true,
41+
printPostContent: true,
42+
43+
silentResponse: false,
44+
45+
regexpFilterText: '$stage',
46+
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
47+
)
2548
}
2649

2750
stages {
@@ -36,6 +59,9 @@ pipeline {
3659
params.verifyPacts == true
3760
}
3861
}
62+
expression {
63+
params.deployOnly == false
64+
}
3965
}
4066
steps {
4167
echo "Building version ${env.VERSION}"
@@ -68,6 +94,9 @@ pipeline {
6894
params.verifyPacts == true
6995
}
7096
}
97+
expression {
98+
params.deployOnly == false
99+
}
71100
}
72101
steps {
73102
sh """
@@ -76,7 +105,7 @@ pipeline {
76105
"""
77106
}
78107
}
79-
stage ('Test providers') {
108+
stage ('Upload pacts') {
80109
when {
81110
anyOf {
82111
not {
@@ -85,12 +114,11 @@ pipeline {
85114
environment name: 'PERFORM_RELEASE', value: 'true'
86115
}
87116
expression {
88-
params.verifyPacts == false
117+
params.verifyPacts == false && params.deployOnly == false
89118
}
90119
}
91120
steps {
92-
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B"
93-
build job: "address-validation-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
121+
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B"
94122
}
95123
}
96124
stage ('Package') {
@@ -102,7 +130,7 @@ pipeline {
102130
environment name: 'PERFORM_RELEASE', value: 'true'
103131
}
104132
expression {
105-
params.verifyPacts == false
133+
params.verifyPacts == false && params.deployOnly == false
106134
}
107135
}
108136
steps {
@@ -118,7 +146,7 @@ pipeline {
118146
environment name: 'PERFORM_RELEASE', value: 'true'
119147
}
120148
expression {
121-
params.verifyPacts == false
149+
params.verifyPacts == false && params.deployOnly == false
122150
}
123151
}
124152
steps {
@@ -147,13 +175,19 @@ pipeline {
147175
stage ('Deploy') {
148176
when {
149177
expression {
150-
params.verifyPacts == false
178+
script {
179+
def deploy = sh script: "pact-broker can-i-deploy --pacticipant delivery-service --version ${env.DEPLOYMENT_VERSION} --to ${env.STAGE} --broker-base-url pact-service:8080", returnStatus: true
180+
return deploy == 0
181+
}
151182
}
152183
anyOf {
153184
not {
154185
branch 'main'
155186
}
156187
environment name: 'PERFORM_RELEASE', value: 'true'
188+
expression {
189+
params.deployOnly == true
190+
}
157191
}
158192
}
159193
steps {

0 commit comments

Comments
 (0)