Skip to content

Commit

Permalink
update apps to webhook
Browse files Browse the repository at this point in the history
  • Loading branch information
schwen authored and ArneLimburg committed Nov 7, 2024
1 parent 7cb8104 commit a584cf8
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 18 deletions.
22 changes: 22 additions & 0 deletions address-validation-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ pipeline {

triggers {
pollSCM("* * * * *")
GenericTrigger(
genericRequestVariables: [
[key: 'stage', regexpFilter: ''],
[key: 'verifyPacts', regexpFilter: '']
],

causeString: 'Triggered by web hook',

token: 'address-validation-service',

printContributedVariables: true,
printPostContent: true,

silentResponse: false,

regexpFilterText: '$stage',
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
)
}

stages {
Expand Down Expand Up @@ -60,6 +78,9 @@ pipeline {
stage ('Test') {
when {
anyOf {
expression {
params.verifyPacts == true
}
not {
branch 'main'
}
Expand Down Expand Up @@ -118,6 +139,7 @@ pipeline {
sh "mvn versions:set scm:checkin -DnewVersion=${nextVersion} -Dmessage='update version to ${nextVersion}' -B"
}
}
sh "curl -H 'Content-Type: application/json' -X PUT http://pact-service:8080/pacticipants/address-validation-service/versions/${env.VERSION}/tags/${env.STAGE}"
}
}
stage ('Deploy') {
Expand Down
20 changes: 19 additions & 1 deletion billing-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ pipeline {

triggers {
pollSCM("* * * * *")
GenericTrigger(
genericRequestVariables: [
[key: 'stage', regexpFilter: ''],
[key: 'verifyPacts', regexpFilter: '']
],

causeString: 'Triggered by web hook',

token: 'billing-service',

printContributedVariables: true,
printPostContent: true,

silentResponse: false,

regexpFilterText: '$stage',
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
)
}

stages {
Expand Down Expand Up @@ -89,7 +107,7 @@ pipeline {
}
}
steps {
sh 'mvn package meecrowave:bundle -DskipTests -B'
sh 'mvn package meecrowave:bundle -Dmaven.test.skip=true -B'
}
}
stage ('Push') {
Expand Down
62 changes: 52 additions & 10 deletions customer-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
pipeline {
agent any

parameters {
booleanParam(name: 'deployOnly', defaultValue: false, description: 'should this job just run to deploy a version')
string(name: 'deploymentVersion', defaultValue: 'latest', description: 'which version should be deployed')
}

options {
disableConcurrentBuilds()
}
Expand All @@ -13,10 +18,30 @@ pipeline {
RELEASE_VERSION = "${env.SNAPSHOT_VERSION.contains('-SNAPSHOT') ? env.SNAPSHOT_VERSION.substring(0, env.SNAPSHOT_VERSION.lastIndexOf('-SNAPSHOT')) : SNAPSHOT_VERSION}"
VERSION = "${env.BRANCH_NAME == 'main' && !env.LAST_COMMIT_MESSAGE.startsWith('update version to ') ? env.RELEASE_VERSION : env.SNAPSHOT_VERSION}"
STAGE = "${env.BRANCH_NAME == 'main' ? 'prod' : 'test'}"
DEPLOYMENT_VERSION = "${params.deploymentVersion != 'latest' ? params.deploymentVersion : env.VERSION}"
}

triggers {
pollSCM("* * * * *")
GenericTrigger(
genericRequestVariables: [
[key: 'stage', regexpFilter: ''],
[key: 'deployOnly', regexpFilter: ''],
[key: 'deploymentVersion', regexpFilter: '']
],

causeString: 'Triggered by web hook',

token: 'customer-service',

printContributedVariables: true,
printPostContent: true,

silentResponse: false,

regexpFilterText: '$stage',
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
)
}

stages {
Expand All @@ -28,6 +53,9 @@ pipeline {
}
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.deployOnly == false
}
}
steps {
echo "Building version ${env.VERSION}"
Expand All @@ -47,29 +75,28 @@ pipeline {
}
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.deployOnly == false
}
}
steps {
sh 'mvn test pact:publish -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B'
sh 'mvn test -DpactBroker.url=http://pact:9292 -Dpact.verifier.publishResults=true -B'
}
}
stage ('Test providers') {
stage ('Upload pacts') {
when {
anyOf {
not {
branch 'main'
}
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.deployOnly == false
}
}
steps {
parallel(
'delivery-service': {
build job: "delivery-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
},
'billing-service': {
build job: "billing-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
}
)
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.consumer.tags=pending-${env.STAGE} -B"
}
}
stage ('Package') {
Expand All @@ -80,6 +107,9 @@ pipeline {
}
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.deployOnly == false
}
}
steps {
sh 'mvn package meecrowave:bundle -DskipTests -B'
Expand All @@ -93,6 +123,9 @@ pipeline {
}
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.deployOnly == false
}
}
steps {
sh 'sshpass -p jenkins scp -o StrictHostKeyChecking=no -P 2222 target/customer-service-meecrowave-distribution.zip jenkins@test:~/'
Expand All @@ -112,11 +145,20 @@ pipeline {
}
stage ('Deploy') {
when {
expression {
script {
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
return deploy == 0
}
}
anyOf {
not {
branch 'main'
}
environment name: 'PERFORM_RELEASE', value: 'true'
expression {
params.deployOnly == true
}
}
}
steps {
Expand Down
48 changes: 41 additions & 7 deletions delivery-service/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pipeline {

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

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

triggers {
pollSCM("* * * * *")
GenericTrigger(
genericRequestVariables: [
[key: 'stage', regexpFilter: ''],
[key: 'verifyPacts', regexpFilter: ''],
[key: 'deployOnly', regexpFilter: ''],
[key: 'deploymentVersion', regexpFilter: '']
],

causeString: 'Triggered by web hook',

token: 'delivery-service',

printContributedVariables: true,
printPostContent: true,

silentResponse: false,

regexpFilterText: '$stage',
regexpFilterExpression: ".*${(env.BRANCH_NAME == 'main' ? 'prod' : 'test')}.*"
)
}

stages {
Expand All @@ -36,6 +59,9 @@ pipeline {
params.verifyPacts == true
}
}
expression {
params.deployOnly == false
}
}
steps {
echo "Building version ${env.VERSION}"
Expand Down Expand Up @@ -68,6 +94,9 @@ pipeline {
params.verifyPacts == true
}
}
expression {
params.deployOnly == false
}
}
steps {
sh """
Expand All @@ -76,7 +105,7 @@ pipeline {
"""
}
}
stage ('Test providers') {
stage ('Upload pacts') {
when {
anyOf {
not {
Expand All @@ -85,12 +114,11 @@ pipeline {
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.verifyPacts == false
params.verifyPacts == false && params.deployOnly == false
}
}
steps {
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B"
build job: "address-validation-service/${env.BRANCH_NAME}", parameters: [booleanParam(name: 'verifyPacts', value: true)]
sh "mvn pact:publish -DpactBroker.url=http://pact-service:8080 -Dpact.verifier.publishResults=true -Dpact.consumer.tags=pending-${env.STAGE} -B"
}
}
stage ('Package') {
Expand All @@ -102,7 +130,7 @@ pipeline {
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.verifyPacts == false
params.verifyPacts == false && params.deployOnly == false
}
}
steps {
Expand All @@ -118,7 +146,7 @@ pipeline {
environment name: 'PERFORM_RELEASE', value: 'true'
}
expression {
params.verifyPacts == false
params.verifyPacts == false && params.deployOnly == false
}
}
steps {
Expand All @@ -140,13 +168,19 @@ pipeline {
stage ('Deploy') {
when {
expression {
params.verifyPacts == false
script {
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
return deploy == 0
}
}
anyOf {
not {
branch 'main'
}
environment name: 'PERFORM_RELEASE', value: 'true'
expression {
params.deployOnly == true
}
}
}
steps {
Expand Down

0 comments on commit a584cf8

Please sign in to comment.