-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathJenkinsfile
More file actions
239 lines (221 loc) · 11.3 KB
/
Jenkinsfile
File metadata and controls
239 lines (221 loc) · 11.3 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
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
229
230
231
232
233
234
235
236
237
238
239
// Syntax check with this command line
// curl -k -X POST -F "jenkinsfile=<Jenkinsfile" https://ci.rssw.eu/pipeline-model-converter/validate
pipeline {
agent none
options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '10'))
timeout(time: 45, unit: 'MINUTES')
skipDefaultCheckout()
}
stages {
stage('🏗️ Class documentation build') {
agent { label 'Windows-Office' }
steps {
checkout([$class: 'GitSCM', branches: scm.branches, extensions: scm.extensions + [[$class: 'CleanCheckout']], userRemoteConfigs: scm.userRemoteConfigs])
script {
def antHome = tool name: 'Ant 1.9', type: 'ant'
def dlc12 = tool name: 'OpenEdge-12.8', type: 'openedge'
def dlc13 = tool name: 'OpenEdge-13.0', type: 'openedge'
def jdk = tool name: 'Corretto 11', type: 'jdk'
def version = readFile('version.txt').trim()
withEnv(["JAVA_HOME=${jdk}"]) {
bat "${antHome}\\bin\\ant -Dpct.release=${version} -DDLC12=${dlc12} -DDLC13=${dlc13} classDoc"
}
}
stash name: 'classdoc', includes: 'dist/classDoc.zip'
}
}
stage('🏗️ Standard build') {
agent { label 'Linux-Office03' }
steps {
script {
checkout([$class: 'GitSCM', branches: scm.branches, extensions: scm.extensions + [[$class: 'CleanCheckout']], userRemoteConfigs: scm.userRemoteConfigs])
// Ugly workaround: sonar-scanner requires the main branch to be present, but Jenkins only fetches the current branch
// An extra checkout is then done with a different refspec.
// There's probably a better way to do that, but no time for that (today)
checkout([$class: 'GitSCM', branches: scm.branches, extensions: scm.extensions + [[$class: 'CleanCheckout']], userRemoteConfigs: [[credentialsId: scm.userRemoteConfigs.credentialsId[0], url: scm.userRemoteConfigs.url[0], refspec: '+refs/heads/main:refs/remotes/origin/main']] ])
unstash name: 'classdoc'
env.GIT_AUTHOR = sh (script: 'git log --format="%ae" -n 1', returnStdout: true).trim()
sh 'git rev-parse --short HEAD > head-rev'
def commit = readFile('head-rev').trim()
def version = readFile('version.txt').trim()
// Compile Java code first
docker.image('docker.rssw.eu/progress/dlc:12.8').inside('') {
sh "ant build"
}
docker.image('docker.rssw.eu/progress/dlc:13.0').inside('') {
sh "ant -Dpct.release=${version} -DDLC12=/ -DDLC13=/opt/progress/dlc pbuild"
}
docker.image('docker.rssw.eu/progress/dlc:12.8').inside('') {
sh "ant -Dpct.release=${version} -DDLC12=/opt/progress/dlc -DDLC13=/ -DGIT_COMMIT=${commit} dist"
}
}
stash name: 'unsigned', includes: 'dist/PCT.jar,eToken.cfg'
}
}
stage('🔏 Package signature') {
agent { label 'Windows-Office02' }
environment {
KEYSTORE_ALIAS = credentials('KEYSTORE_ALIAS')
KEYSTORE_PASS = credentials('KEYSTORE_PASS')
}
steps {
unstash name: 'unsigned'
script {
withEnv(["PATH+JAVA=${tool name: 'JDK17', type: 'jdk'}\\bin"]) {
bat "jarsigner -tsa http://timestamp.sectigo.com -keystore NONE -storepass %KEYSTORE_PASS% -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg .\\eToken.cfg -signedjar dist\\PCT-signed.jar dist\\PCT.jar %KEYSTORE_ALIAS%"
}
}
stash name: 'signed', includes: 'dist/PCT-signed.jar'
}
}
stage('📦 Archive') {
agent { label 'Linux-Office03' }
steps {
unstash name: 'signed'
stash name: 'tests', includes: 'dist/PCT.jar,dist/PCT-signed.jar,dist/testcases.zip,tests.xml'
archiveArtifacts 'dist/PCT.jar,dist/PCT-signed.jar,dist/PCT-javadoc.jar,dist/PCT-sources.jar'
}
}
stage('🧪 Unit tests') {
steps {
parallel branch1: { testBranch('Windows-Office', 'Corretto 11', 'Ant 1.10', 'OpenEdge-12.2', true, '12.2-Win', '') },
branch2: { testBranch('Windows-Office02', 'JDK17', 'Ant 1.10', 'OpenEdge-12.8', true, '12.8-Win', '') },
branch3: { testBranch('Linux-Office03', 'Corretto 11', 'Ant 1.10', 'OpenEdge-12.2', false, '12.2-Linux', 'docker.rssw.eu/progress/dlc:12.2') },
branch4: { testBranch('Linux-Office03', 'Corretto 11', 'Ant 1.10', 'OpenEdge-12.8', true, '12.8-Linux', 'docker.rssw.eu/progress/dlc:12.8') },
branch5: { testBranch('Linux-Office03', 'JDK17', 'Ant 1.10', 'OpenEdge-13.0', true, '13.0-Linux', 'docker.rssw.eu/progress/dlc:13.0') },
branch6: { testBranch('Windows-Office', 'JDK17', 'Ant 1.10', 'OpenEdge-13.0', true, '13.0-Win', '') },
failFast: false
}
}
stage('🗃️ Unit tests reports') {
agent { label 'Linux-Office03' }
steps {
// Wildcards not accepted in unstash...
unstash name: 'junit-12.2-Win'
unstash name: 'junit-12.8-Win'
unstash name: 'junit-13.0-Win'
unstash name: 'junit-12.2-Linux'
unstash name: 'junit-12.8-Linux'
unstash name: 'junit-13.0-Linux'
sh "mkdir junitreports"
unzip zipFile: 'junitreports-12.2-Win.zip', dir: 'junitreports', quiet: true
unzip zipFile: 'junitreports-12.8-Win.zip', dir: 'junitreports', quiet: true
unzip zipFile: 'junitreports-13.0-Win.zip', dir: 'junitreports', quiet: true
unzip zipFile: 'junitreports-12.2-Linux.zip', dir: 'junitreports', quiet: true
unzip zipFile: 'junitreports-12.8-Linux.zip', dir: 'junitreports', quiet: true
unzip zipFile: 'junitreports-13.0-Linux.zip', dir: 'junitreports', quiet: true
junit 'junitreports/**/*.xml'
}
}
stage('🔍️ Sonar') {
agent { label 'Linux-Office03' }
steps {
unstash name: 'coverage-12.2-Win'
unstash name: 'coverage-12.8-Win'
unstash name: 'coverage-12.8-Linux'
unstash name: 'coverage-13.0-Win'
unstash name: 'coverage-13.0-Linux'
script {
def version = readFile('version.txt').trim()
docker.image('docker.rssw.eu/progress/dlc:12.8').inside('') {
sh 'ant -lib lib/jacocoant-0.8.14.jar -file sonar.xml -DDLC=/opt/progress/dlc init-sonar'
}
docker.image('sonarsource/sonar-scanner-cli:latest').inside('') {
withSonarQubeEnv('RSSW') {
withEnv(["SONAR_USER_HOME=/tmp"]) {
if ("main" == env.BRANCH_NAME) {
sh "sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.projectVersion=${version}"
} else {
sh "sonar-scanner -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.newCode.referenceBranch=main -Dsonar.branch.target=main -Dsonar.projectVersion=${version}"
}
}
}
}
}
}
}
stage('📦 Maven Central') {
environment {
MAVEN_GPG_PASSPHRASE=credentials('GPG_KEY')
BEARER_TOKEN=credentials('MavenCentralBearer')
}
agent { label 'Linux-Office03' }
steps {
script {
def jdk = tool name: 'JDK17', type: 'jdk'
def mvn = tool name: 'Maven 3', type: 'maven'
def ant = tool name: 'Ant 1.10', type: 'ant'
def version = readFile('version.txt').trim()
withEnv(["MAVEN_HOME=${mvn}", "JAVA_HOME=${jdk}"]) {
if (!version.endsWith('-pre')) {
// Manually create and upload bundle to Maven Central. It's probably possible to do that with the maven-publish plugin, but as build is done with Ant, it's easier to do it manually.
// https://central.sonatype.org/publish/publish-portal-api/
// https://central.sonatype.org/publish/publish-portal-upload/
sh "mkdir bundle && cp alt-pom.xml bundle/pct-${version}.pom && cp dist/PCT.jar bundle/pct-${version}.jar && cp dist/PCT-sources.jar bundle/pct-${version}-sources.jar && cp dist/PCT-javadoc.jar bundle/pct-${version}-javadoc.jar"
sh "gpg --pinentry-mode loopback --passphrase \${MAVEN_GPG_PASSPHRASE} --armor --output bundle/pct-${version}.jar.asc --detach-sign bundle/pct-${version}.jar"
sh "gpg --pinentry-mode loopback --passphrase \${MAVEN_GPG_PASSPHRASE} --armor --output bundle/pct-${version}-sources.jar.asc --detach-sign bundle/pct-${version}-sources.jar"
sh "gpg --pinentry-mode loopback --passphrase \${MAVEN_GPG_PASSPHRASE} --armor --output bundle/pct-${version}-javadoc.jar.asc --detach-sign bundle/pct-${version}-javadoc.jar"
sh "gpg --pinentry-mode loopback --passphrase \${MAVEN_GPG_PASSPHRASE} --armor --output bundle/pct-${version}.pom.asc --detach-sign bundle/pct-${version}.pom"
sh "${ant}/bin/ant -Dversion=${version} central-bundle"
sh 'curl --request POST --header "Authorization: Bearer \${BEARER_TOKEN}" --form bundle=@central-bundle.zip \'https://central.sonatype.com/api/v1/publisher/upload?name=pct&publishingType=USER_MANAGED\''
mail body: "https://central.sonatype.com/publishing/deployments", to: "g.querret@riverside-software.fr", subject: "pct - Publish artifact on Central"
}
}
}
}
}
}
post {
unstable {
script {
mail body: "Check console output at ${BUILD_URL}console", to: "jenkins-reports@riverside-software.fr,${env.GIT_AUTHOR}", subject: "PCT ${BRANCH_NAME} build is unstable"
}
}
failure {
script {
mail body: "Check console output at ${BUILD_URL}console", to: "jenkins-reports@riverside-software.fr,${env.GIT_AUTHOR}", subject: "PCT ${BRANCH_NAME} build failure"
}
}
fixed {
script {
mail body: "Console output at ${BUILD_URL}console", to: "jenkins-reports@riverside-software.fr,${env.GIT_AUTHOR}", subject: "PCT ${BRANCH_NAME} build is back to normal"
}
}
}
}
def testBranch(nodeName, jdkVersion, antVersion, dlcVersion, stashCoverage, label, dockerImg) {
node(nodeName) {
ws {
deleteDir()
def dlc = tool name: dlcVersion, type: 'openedge'
def jdk = tool name: jdkVersion, type: 'jdk'
def antHome = tool name: antVersion, type: 'ant'
unstash name: 'tests'
if (isUnix()) {
configFileProvider([configFile(fileId: 'MvnSettingsRSSW', targetLocation: 'tmpDir/settings.xml')]) {
docker.image(dockerImg).inside('') {
sh "mkdir local_repo"
sh "> pwd.txt pwd"
def pwd = readFile('pwd.txt').trim()
withEnv(["MAVEN_SETTINGS=${pwd}/tmpDir/settings.xml", "LOCAL_M2_REPO=${pwd}/local_repo"]) {
sh "ant -DDLC=/opt/progress/dlc -DPROFILER=true -DTESTENV=${label} -lib dist/PCT-signed.jar -f tests.xml init dist"
}
}
}
} else {
configFileProvider([configFile(fileId: 'MvnSettingsRSSW', variable: 'MAVEN_SETTINGS')]) {
withEnv(["JAVA_HOME=${jdk}"]) {
bat "${antHome}/bin/ant -lib dist/PCT.jar -DDLC=${dlc} -DPROFILER=true -DTESTENV=${label} -f tests.xml init dist"
}
}
}
stash name: "junit-${label}", includes: 'junitreports-*.zip'
archiveArtifacts 'emailable-report-*.html'
if (stashCoverage) {
stash name: "coverage-${label}", includes: "profiler/jacoco-${label}.exec,oe-profiler-data-${label}.zip"
}
}
}
}