-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJenkinsfile
More file actions
118 lines (114 loc) · 5.41 KB
/
Copy pathJenkinsfile
File metadata and controls
118 lines (114 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env groovy
pipeline {
agent {
label 'maven-3-9-5-eclipse-temurin-21'
}
environment {
TAG = "${env.BRANCH_NAME.replace('/','-')}"
MAVEN_OPTS="-Xmx1g"
MINIO_HOST = "http://192.168.250.150:9000"
MINIO_CREDENTIALS = "jenkins-ci-minio"
REGISTRY = "registry.integratedmodelling.org"
REGISTRY_CREDENTIALS = "registry-jenkins-credentials"
VERSION_DATE = sh(
script: "date '+%Y-%m-%dT%H:%M:%S'",
returnStdout: true).trim()
RESOURCES_CONTAINER = "resources-service-21"
RESOURCE_SERVICE = "resources-main"
RUNTIME_CONTAINER = "runtime-service-21"
RUNTIME_SERVICE = "runtime-main"
RESOLVER_CONTAINER = "resolver-service-21"
RESOLVER_SERVICE = "resolver-main"
REASONER_CONTAINER = "reasoner-service-21"
REASONER_SERVICE = "reasoner-main"
BASE_CONTAINER = "klab-base-21:dd2b778c852f20ad9c82fe6e12d5723e23e3dd19"
DOCKER_HOST = "192.168.250.215"
DOCKER_STACK = "klab"
}
stages {
stage('Maven Build') {
steps {
script {
def jibArgs = 'jib:build -Djib.httpTimeout=180000'
def dockerBuild = sh(script: "git log -1 --pretty=%B | grep -qi '\\[docker build\\]'", returnStatus: true)
def publishBranch = env.BRANCH_NAME in ['master', 'develop']
def mavenPhase = publishBranch ? 'deploy' : 'install'
env.JIB_ARGS = (publishBranch || dockerBuild == 0) ? jibArgs : ''
env.MAVEN_PHASE = mavenPhase
echo "${env.BRANCH_NAME} build with container tag: ${env.TAG}"
echo "Running Maven phase: ${env.MAVEN_PHASE}"
configFileProvider([
configFile(
fileId: '1f5f24a2-9839-4194-b2ad-0613279f9fba',
variable: 'MAVEN_SETTINGS_XML'
)
]) {
withCredentials([
usernamePassword(
credentialsId: env.REGISTRY_CREDENTIALS,
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)
]) {
sh '''
./mvnw --settings "$MAVEN_SETTINGS_XML" clean source:jar "$MAVEN_PHASE" -DskipTests -U $JIB_ARGS
'''
}
}
}
}
}
stage('Deploy artifacts') {
when {
anyOf { branch 'develop'; branch 'master' }
}
steps {
withCredentials([sshUserPrivateKey(credentialsId: 'jenkins-im-communication', keyFileVariable: 'identity')]) {
sh './mvnw --projects klab.core.api javadoc:javadoc'
sh 'rsync --archive --progress --delete --rsh="ssh -i ${identity} -o StrictHostKeyChecking=no" klab.core.api/target/reports/apidocs/ ubuntu@192.168.250.200:repos/documents.production.compose/javadocs/'
}
withCredentials([usernamePassword(credentialsId: "${env.MINIO_CREDENTIALS}", passwordVariable: 'SECRETKEY', usernameVariable: 'ACCESSKEY')]) {
sh 'mc alias set minio $MINIO_HOST $ACCESSKEY $SECRETKEY'
sh """
mc rm --recursive --force minio/klab/products/klab/ || echo "klab/products/klab/ does not exists"
mc cp --recursive ./klab.distribution/target/distribution/ minio/klab/products/klab
"""
}
}
}
stage('Update services') {
when {
expression { env.JIB != '' }
}
steps {
script {
// Each service image to pull and update
def services = [
[name: "${REASONER_SERVICE}", container: "${REASONER_CONTAINER}"],
[name: "${RESOLVER_SERVICE}", container: "${RESOLVER_CONTAINER}"],
[name: "${RUNTIME_SERVICE}", container: "${RUNTIME_CONTAINER}"],
[name: "${RESOURCE_SERVICE}", container: "${RESOURCES_CONTAINER}"]
]
sshagent(["bc3-im-services"]) {
services.each { svc ->
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l bc3 ${DOCKER_HOST} '
echo "Updating ${svc.name} service..."
docker pull ${REGISTRY}/${svc.container}:${TAG}
'
"""
}
// Once all images are pulled, recreate containers via docker compose
sh """
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -l bc3 ${DOCKER_HOST} '
cd ~/repos/klab-services-infrastructure/docker || exit 1
echo "Bringing up updated containers..."
docker compose up -d
'
"""
}
}
}
}
}
}