forked from integratedmodelling/klab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
228 lines (201 loc) · 9.34 KB
/
Jenkinsfile
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env groovy
def kmodelers = [
"unix": "org.integratedmodelling.klab.modeler.product-linux.gtk.x86_64.zip",
"win": "org.integratedmodelling.klab.modeler.product-win32.win32.x86_64.zip",
"macos": "org.integratedmodelling.klab.modeler.product-macosx.cocoa.x86_64.zip",
]
pipeline {
agent { label "mvn-java-agent"}
options { skipDefaultCheckout(true) }
parameters {
string(name: 'BRANCH',
defaultValue: '',
description :'Which branch should be used for the build?\n' +
'Empty is the default value and will generate build on the latest commit'
)
string(name: 'TAG',
defaultValue: '',
description: 'Variable used for tagging the container images or generating ' +
'a build based on a tagged commit. Default is empty and the tag is determined ' +
'by the most recent commit.'
)
string(name: 'MINIO_HOST',
defaultValue: 'http://192.168.250.224:9000',
description: 'Minio host used to archive files'
)
string(name: 'MINIO_CREDENTIALS',
defaultValue: 'bc42afcf-7037-4d23-a7cb-6c66b8a0aa45',
description: 'Minio credentials used to be used by job'
)
string(name: 'REGISTRY_CREDENTIALS',
defaultValue: '83f9fb8b-e503-4566-9784-e80f2f2d7c64',
description: 'Docker registry credentials used to be used by job'
)
string(
name: 'GIT_CREDENTIALS',
defaultValue: '2f30d924-29e5-4235-b61f-a0dbe2bb7783',
description: 'Git Credentials'
)
}
environment {
VERSION_DATE = sh(
script: "date '+%Y-%m-%dT%H:%M:%S'",
returnStdout: true).trim()
MAVEN_OPTS="--illegal-access=permit"
REGISTRY = "registry.integratedmodelling.org"
STAT_CONTAINER = "stat-server-16"
ENGINE_CONTAINER = "engine-server-16"
HUB_CONTAINER = "hub-server-16"
NODE_CONTAINER = "node-server-16"
BASE_CONTAINER = "klab-base-16"
MAIN = "master"
DEVELOP = "develop"
PRODUCTS_GEN = "yes"
}
stages {
/*
We pull the repo to start, this also is used as a for web hook monitoring by jenkins
and github.
*/
stage ('Clone Repo') {
steps {
checkout scm
withCredentials(
[usernamePassword(
credentialsId: "${params.MINIO_CREDENTIALS}",
passwordVariable: 'SECRETKEY',
usernameVariable: 'ACCESSKEY'
)
]){ sh 'mc alias set minio $MINIO_HOST $ACCESSKEY $SECRETKEY' }
script {
if (TAG.isEmpty() == false) {
echo "Tag parameterize"
sh "git checkout tags/${TAG} -b latest"
BRANCH = MAIN
env.TAG = TAG
} else {
if (BRANCH.isEmpty() == false) {
echo "Branch parameterize"
} else {
echo "Unparameterize checkout of latest commit"
BRANCH = sh(returnStdout: true,
script: 'git for-each-ref --count=1 --sort=-committerdate ' +
'--format="%(refname:short)"').trim().replace("origin/", "")
}
sh "git checkout ${BRANCH}"
env.TAG = BRANCH.replace("/","-")
if (BRANCH == MAIN) {
env.BRANCH = MAIN
env.TAG = "latest"
echo "Latest"
} else if (BRANCH == DEVELOP) {
env.BRANCH = DEVELOP
env.TAG = DEVELOP
echo "Develop"
} else {
PRODUCTS_GEN = "no"
echo "Other: ${BRANCH}"
}
}
env.SNAPSHOT = sh(
returnStdout: true,
script: 'mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate ' +
'-Dexpression=project.version -q -DforceStdout ' +
'--batch-mode -U -e -Dsurefire.useFile=false').trim()
env.CURRENT_COMMIT = sh (
script: 'git rev-parse --verify HEAD',
returnStdout: true).trim()
env.LATEST_TAGGED_COMMIT = sh (
script: 'git describe --tags `git rev-list --tags --max-count=1` | xargs git rev-list -n 1',
returnStdout: true).trim()
env.LATEST_TAG = sh (
script: 'git describe --tags `git rev-list --tags --max-count=1`',
returnStdout: true).trim()
if (BRANCH.isEmpty() == true && env.CURRENT_COMMIT == env.LATEST_TAGGED_COMMIT) {
echo "Tagged commit build ${LATEST_TAGGED_COMMIT} with tag ${LATEST_TAG}"
env.TAG = env.LATEST_TAG
PRODUCTS_GEN = "yes"
}
env.BRANCH = BRANCH
currentBuild.description = "${BRANCH} build with container tag: ${env.TAG}"
echo "${BRANCH} build with container tag: ${env.TAG} and products generations is ${PRODUCTS_GEN}"
}
}
}
stage ('Update Version.java') {
steps {
sh "cd api/org.integratedmodelling.klab.api/src/org/integratedmodelling/klab && " +
"sed -i 's;\"VERSION_BRANCH;\"${env.BRANCH};g' Version.java &&" +
"sed -i 's;\"VERSION_COMMIT;\"${env.CURRENT_COMMIT};g' Version.java &&" +
"sed -i 's;\"VERSION_BUILD;\"${env.BUILD_NUMBER};g' Version.java && " +
"sed -i 's;\"VERSION_DATE;\"${env.VERSION_DATE};g' Version.java"
}
}
stage('Maven install with jib') {
steps {
withCredentials([usernamePassword(credentialsId: "${params.REGISTRY_CREDENTIALS}", passwordVariable: 'PASSWORD', usernameVariable: 'USERNAME')]) {
sh 'export JAVA_HOME=/opt/java16/openjdk && mvn clean install -U -DskipTests jib:build -Djib.httpTimeout=60000'
}
}
}
stage('Push products') {
when {
expression { PRODUCTS_GEN == "yes" }
}
steps {
pushProducts(env.TAG, kmodelers)
}
}
}
}
def pushProducts(destination, kmodelers) {
prepareCliUpload(destination)
prepareKmodelersUpload(kmodelers,destination)
uploadProducts(destination)
}
def prepareCliUpload(destination) {
sh """mkdir -p ${WORKSPACE}/minio/${destination}/cli
cp products/cli/target/cli-*-SNAPSHOT.jar ${WORKSPACE}/minio/${destination}/cli
cp -r products/cli/target/lib ${WORKSPACE}/minio/${destination}/cli
cd ${WORKSPACE}/minio/${destination}/cli
touch product.properties
echo "klab.product.name=k.LAB Engine" >> product.properties
echo "klab.product.description=The k.LAB modeling engine" >> product.properties
echo "klab.product.type=JAR" >> product.properties
echo "klab.product.build.version=${env.SNAPSHOT}" >> product.properties
echo "klab.product.build.time=${VERSION_DATE}" >> product.properties
echo "klab.product.build.main=org.integratedmodelling.klab.k.Main" >> product.properties
md5sum `find . -type f -print` > filelist.txt
"""
}
def uploadProducts(destination){
sh """
mc rm --recursive --force minio/products/klab/${destination} || echo "${destination} does not exists"
mc cp --recursive ${WORKSPACE}/minio/${destination} minio/products/klab/
"""
}
def prepareKmodelersUpload(list, destination) {
dir ("${WORKSPACE}/minio/${destination}/kmodeler/") {
sh """touch product.properties
rm product.properties
touch product.properties
echo "klab.product.name=k.LAB Modeler" >> product.properties
echo "klab.product.description=The k.LAB modeler interface" >> product.properties
echo "klab.product.type=ECLIPSE" >> product.properties
echo "klab.product.osspecific=true" >> product.properties
echo "klab.product.build.version=${env.SNAPSHOT}" >> product.properties
echo "klab.product.build.time=${VERSION_DATE}" >> product.properties
"""
}
list.each { element ->
dir ("${WORKSPACE}/minio/${destination}/kmodeler/${element.key}") {
unzip zipFile: "${WORKSPACE}/ide/org.integratedmodelling.klab.ide.repository/target/products/${element.value}", quiet: true
if(element.key != "macos") {
sh """cd kmodeler && md5sum `find . -type f` > filelist.txt && mv * .."""
sh """rm -r kmodeler"""
} else {
sh """md5sum `find . -type f` > filelist.txt"""
}
}
}
}