Repository navigation
Expand file tree
/
Copy pathJenkinsfile.BuildWindowsRelease
More file actions
263 lines (254 loc) · 14.7 KB
/
Copy pathJenkinsfile.BuildWindowsRelease
File metadata and controls
263 lines (254 loc) · 14.7 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
// Jenkins pipeline that builds the OpenModelica Windows installer: the nightly build, a
// maintenance build, a release or a pull request build, depending on GIT_BRANCH.
// It does what the job's batch step and bn.bat (buildNightly64bit.bat) did, but binds the
// eToken password with withCredentials so BuildWindowsRelease.sh can sign from an agent
// running in session 0 (no SafeNet login).
//
// Only the eToken password comes from Jenkins; the certificate file and key container are
// defaults in BuildWindowsRelease.sh (TOKEN_CERT/TOKEN_CONTAINER override them).
//
// Setup
// 1. Jenkins credential: kind "Secret text", id osmc-token-password (or set TOKEN_CREDENTIAL),
// secret = the eToken password. Never put the password in a job config or a file on the node.
// 2. Job: "Pipeline script from SCM", repository OpenModelica/OpenModelicaSetup,
// script path Jenkinsfile.BuildWindowsRelease, "Lightweight checkout" on.
// 3. Node: start the agent from a Task Scheduler task, trigger "At startup", "Run whether user
// is logged on or not" with the password stored, no "Stop the task if it runs longer than".
// Check that the agent runs in session 0:
// Get-CimInstance Win32_Process -Filter "Name='java.exe'" | Select ProcessId, SessionId
// Then the node needs no logged-in session and can reboot unattended.
// 4. Node: C:\dev\sign holds osmc.cer (the signing certificate) and OpenModelica.exe (any
// executable; the build test-signs it first so a signing problem fails within a minute).
// 5. First run: OM_REQUIRE_SIGNING off; after that leave it on so an unsigned installer is
// never shipped.
//
// Certificate renewal (the current certificate expires 2027-07-27)
// 1. With the new certificate on the token, open SafeNet Authentication Client Tools,
// Advanced View, the token, the certificate: note its "Key container name" (p11#...).
// 2. Export the certificate (public part, .cer) over C:\dev\sign\osmc.cer.
// 3. Update the TOKEN_CONTAINER default in BuildWindowsRelease.sh (or set TOKEN_CONTAINER in the
// job environment) and run one build to check that the test signing passes.
// The container name cannot be read without the password and the certificate is in no
// certificate store when no one is logged in, which is why they are not looked up at run time.
//
// Encryption build (OM_ENABLE_ENCRYPTION, replaces build-encryption.bat)
// Use a second job on this same Jenkinsfile with OM_ENABLE_ENCRYPTION on. It builds in its own
// tree, c:\dev\e\OM64bit, releases go to c:\dev\OpenModelica_releases\e and are uploaded
// to nightly-builds/e/64bit with the -encryption suffix. PrepareEncryption.sh clones or updates
// OMEncryption in that tree and decrypts the SEMLA private keys, which needs on the node:
// - C:\OMEncryptionNeeds\OMPublicKey, a git checkout holding public_key_tool.pem;
// - the passphrase of the private keys: a Jenkins "Secret text" credential named by
// ENCRYPTION_KEY_CREDENTIAL or, when that is empty, C:\OMEncryptionNeeds\pass-gpg-key.txt.
// Both jobs take the windows-release-build lock (Lockable Resources plugin): they kill each
// other's omc.exe in Prepare and would share the build machine otherwise.
//
// Maintenance and release builds
// Give GIT_BRANCH as maintenance/vX.Y to build the head of that maintenance branch or as a
// tag, vX.Y.Z or vX.Y.Z-dev.beta.N, to build that release. BuildWindowsRelease.sh uploads
// them to releases/X.Y/maintenance/64bit and releases/X.Y/Z[-suffix]/64bit (the nightly
// build goes to nightly-builds/64bit) and ships the users guide of X.Y once it is
// published. Only an installer built from a tag is a release for the installer, anything
// else installs as a nightly build. UPLOAD_DIR sends the installer elsewhere.
// The directories are created on the server by the upload, so SSHUSER has to be allowed to
// make releases/X.Y there. With OM_ENABLE_ENCRYPTION the upload goes to e/64bit below them,
// where e is a link to encryption/ and that gets the .htaccess of the nightly encryption
// builds, so that the installer is behind the password from the start.
// A release series is built in a directory of its own, C:\OM128 for maintenance/v1.28 and
// the v1.28.* tags, with the same layout as c:\dev: OM64bit, OpenModelica_releases and its own
// OMDev, C:\OM128\OMDev, on the maintenance/v1.28 branch of OMDevUCRT. That branch has to
// exist before the first build. BUILD_ROOT and OMDEV_BRANCH override the two. The directory
// is created and filled by the first build.
// Use a job of its own per maintenance branch on this same Jenkinsfile, and one for the
// releases where the tag is typed in. They take the same lock as the nightly build.
//
// Pull request build (replaces buildNightly64bitPRbuild.bat)
// Give GIT_BRANCH as #NUMBER, for instance #14016, to build the head of that OpenModelica
// pull request. BuildWindowsRelease.sh fetches it into the local branch PR_NUMBER_experimental,
// names the installer OpenModelica-<revision>_PR_NUMBER_experimental-64bit.exe and uploads it
// to nightly-builds/PRbuilds/64bit. Use a job of its own on this same Jenkinsfile so the
// nightly job keeps its history and schedule; it builds in the tree of the nightly build and
// takes the same lock.
// The installer is signed like any other, so only build pull requests whose code you trust.
// The first build after a parameter is added runs before Jenkins knows it, so params.X is null
// there: the helpers and the environment below take a missing parameter as its default.
// the release series of a maintenance branch or a release tag: 1.28 for maintenance/v1.28,
// v1.28.0 and v1.28.0-dev.beta.1, empty for anything else
def omSeries(String ref) {
def r = (ref ?: '').trim().replaceFirst('^maintenance/', '')
if (!r.matches('v[0-9]+\\.[0-9]+(\\..*)?')) {
return ''
}
def parts = r.substring(1).split('\\.')
return parts[0] + '.' + parts[1]
}
// where everything is built: c:\dev, or C:\OM128 for the 1.28 series
def omBuildRoot(String root, String ref) {
if (root?.trim()) {
return root.trim().replace('/', '\\').replaceAll('\\\\+$', '')
}
def series = omSeries(ref)
return series ? 'C:\\OM' + series.replace('.', '') : 'c:\\dev'
}
// the nightly build uses C:\OMDevUCRT, a release series the OMDev in its own directory
def omDevDir(String root, String ref) {
def buildRoot = omBuildRoot(root, ref)
return buildRoot.equalsIgnoreCase('c:\\dev') ? 'C:\\OMDevUCRT' : buildRoot + '\\OMDev'
}
def omDevBranch(String branch, String ref) {
if (branch?.trim()) {
return branch.trim()
}
def series = omSeries(ref)
return series ? 'maintenance/v' + series : 'master'
}
// c:\dev\e as /c/dev/e
def omMsysPath(String path) {
return '/' + path.substring(0, 1).toLowerCase() + path.substring(2).replace('\\', '/')
}
pipeline {
// only the node with the eToken can sign; the label is fixed here, not a parameter, so a
// build cannot be sent elsewhere and the first run (before Jenkins knows the parameters)
// still finds the node
agent { label 'windows.openmodelica.org' }
options {
disableConcurrentBuilds()
timestamps()
buildDiscarder(logRotator(numToKeepStr: '30'))
timeout(time: 12, unit: 'HOURS')
// the nightly and the encryption job run on the same node, one at a time
lock(resource: 'windows-release-build')
// the build uses the fixed layout below c:\dev or C:\OM<series>, not the workspace
skipDefaultCheckout()
}
parameters {
string(name: 'GIT_BRANCH', defaultValue: 'master', description: 'What to build: master for the nightly build, maintenance/vX.Y for a maintenance build, a tag such as v1.28.0 for a release, or #NUMBER (for instance #14016) for that pull request')
string(name: 'BUILD_ROOT', defaultValue: '', description: 'Directory on the node to build in; empty to pick it from GIT_BRANCH: C:\\OM128 for maintenance/v1.28 and the v1.28.* tags, c:\\dev for anything else')
string(name: 'OMDEV_BRANCH', defaultValue: '', description: 'OMDevUCRT branch to build with; empty to pick it from GIT_BRANCH: maintenance/v1.28 for maintenance/v1.28 and the v1.28.* tags, master for anything else')
string(name: 'SSHUSER', defaultValue: 'adrpo', description: 'User on build.openmodelica.org that the installer is uploaded as')
string(name: 'UPLOAD_DIR', defaultValue: '', description: 'Directory on build.openmodelica.org below omc/builds/windows/ to upload to, for instance releases/1.28/maintenance; empty to pick it from GIT_BRANCH')
booleanParam(name: 'FORCE_BUILD', defaultValue: false, description: 'Delete the previous builds in OpenModelica_releases so an already built version is built again')
string(name: 'MAKETHREADS', defaultValue: '-j16', description: 'Parallel make flag passed to BuildWindowsRelease.sh')
booleanParam(name: 'OM_REQUIRE_SIGNING', defaultValue: true, description: 'Fail the build instead of shipping an unsigned installer')
booleanParam(name: 'OM_ENABLE_ENCRYPTION', defaultValue: false, description: 'Build the encryption-enabled release')
string(name: 'ENCRYPTION_KEY_CREDENTIAL', defaultValue: '', description: 'Id of the Jenkins secret-text credential holding the passphrase of the OMEncryption private keys, empty to read it from C:\\OMEncryptionNeeds\\pass-gpg-key.txt')
string(name: 'TOKEN_CREDENTIAL', defaultValue: 'osmc-token-password', description: 'Id of the Jenkins secret-text credential holding the eToken password, empty to sign via the SafeNet single sign-on')
}
environment {
OM_BUILD_ROOT = "${omBuildRoot(params.BUILD_ROOT, params.GIT_BRANCH)}"
OMDEV = "${omDevDir(params.BUILD_ROOT, params.GIT_BRANCH)}"
OMDEV_BRANCH = "${omDevBranch(params.OMDEV_BRANCH, params.GIT_BRANCH)}"
OMDEV_MSYSTEM = 'UCRT64'
// BuildWindowsRelease.sh uploads with $HOME/.ssh/id_rsa
HOME = '/c/dev/'
// "#NUMBER" is a pull request; a # would start a comment in the sh command line, so pass
// the name of the branch that BuildWindowsRelease.sh fetches the pull request into
OM_GIT_BRANCH = "${(params.GIT_BRANCH ?: 'master').trim().matches('#[0-9]+') ? 'PR_' + (params.GIT_BRANCH ?: 'master').trim().substring(1) + '_experimental' : (params.GIT_BRANCH ?: 'master').trim()}"
OM_UPLOAD_DIR = "${(params.UPLOAD_DIR ?: '').trim()}"
OM_SSHUSER = "${(params.SSHUSER ?: '').trim() ?: 'adrpo'}"
OM_REQUIRE_SIGNING = "${params.OM_REQUIRE_SIGNING ? 'yes' : ''}"
OM_ENABLE_ENCRYPTION = "${params.OM_ENABLE_ENCRYPTION ? 'yes' : ''}"
// BuildWindowsRelease.sh builds the encryption release in e\OM64bit
OM_DIR = "${omBuildRoot(params.BUILD_ROOT, params.GIT_BRANCH) + (params.OM_ENABLE_ENCRYPTION ? '\\e' : '') + '\\OM64bit'}"
OM_DIR_MSYS = "${omMsysPath(omBuildRoot(params.BUILD_ROOT, params.GIT_BRANCH) + (params.OM_ENABLE_ENCRYPTION ? '\\e' : '') + '\\OM64bit')}"
OM_RELEASES = "${omBuildRoot(params.BUILD_ROOT, params.GIT_BRANCH) + '\\OpenModelica_releases' + (params.OM_ENABLE_ENCRYPTION ? '\\e' : '')}"
}
stages {
stage('Prepare') {
steps {
script {
if ((params.GIT_BRANCH ?: 'master').trim().matches('#[0-9]+')) {
currentBuild.displayName = "#${env.BUILD_NUMBER} PR ${(params.GIT_BRANCH ?: 'master').trim().substring(1)}"
}
}
// kill leftovers from a previous build; taskkill fails when nothing runs
bat '''
taskkill /F /IM omc.exe /T
taskkill /F /IM perl.exe /T
exit /b 0
'''
script {
if (params.FORCE_BUILD) {
echo 'Forcing build ... deleting the previous builds'
bat '''
for /d %%G in ("%OM_RELEASES%\\v*") do rd /s /q "%%~G"
exit /b 0
'''
}
}
bat '''
set "PATH=%PATH%;C:\\Program Files\\TortoiseSVN\\bin\\;c:\\bin\\jdk\\bin;c:\\bin\\nsis\\;c:\\bin\\git\\bin;c:\\Program Files\\Git\\bin"
echo OM_BUILD_ROOT: %OM_BUILD_ROOT%
echo OMDEV: %OMDEV% on %OMDEV_BRANCH%
if not exist c:\\dev\\ md c:\\dev\\
if not exist "%OM_BUILD_ROOT%\\" md "%OM_BUILD_ROOT%"
if not exist "%OMDEV%" (
git clone --branch "%OMDEV_BRANCH%" https://gitlab.liu.se/OpenModelica/OMDevUCRT.git "%OMDEV%" || exit /b 1
cd /d "%OMDEV%" || exit /b 1
call SETUP_OMDEV.bat || exit /b 1
)
if not exist "%OM_RELEASES%\\" md "%OM_RELEASES%"
if not exist c:\\dev\\OMTLMSimulator\\ (
cd /d c:\\dev\\ || exit /b 1
git clone https://github.com/OpenModelica/OMTLMSimulator.git OMTLMSimulator || exit /b 1
)
if not exist "%OM_DIR%\\" (
git clone --recursive https://github.com/OpenModelica/OpenModelica.git "%OM_DIR%" || exit /b 1
)
if not exist "%OM_DIR%\\OMSetup\\" (
git clone https://github.com/OpenModelica/OpenModelicaSetup "%OM_DIR%\\OMSetup" || exit /b 1
)
rem update the build script first
cd /d "%OM_DIR%\\OMSetup" || exit /b 1
git pull || exit /b 1
rem update OMDev
cd /d "%OMDEV%" || exit /b 1
git fetch origin || exit /b 1
git checkout "%OMDEV_BRANCH%" || exit /b 1
git checkout . || exit /b 1
git pull || exit /b 1
'''
script {
if (params.OM_ENABLE_ENCRYPTION) {
// OM_ENCRYPTION_KEY_PW only reaches the script through the environment
def prepare = {
bat '''
set "PATH=%PATH%;c:\\bin\\git\\bin;c:\\Program Files\\Git\\bin"
set MSYSTEM=%OMDEV_MSYSTEM%
"%OMDEV%\\tools\\msys\\usr\\bin\\sh" --login -c "sh %OM_DIR_MSYS%/OMSetup/PrepareEncryption.sh %OM_DIR_MSYS%"
'''
}
if (params.ENCRYPTION_KEY_CREDENTIAL) {
withCredentials([string(credentialsId: params.ENCRYPTION_KEY_CREDENTIAL, variable: 'OM_ENCRYPTION_KEY_PW')]) {
prepare()
}
} else {
prepare()
}
}
}
}
}
stage('Build and sign') {
steps {
script {
// TOKEN_PW only reaches the script through the environment, never the command line
def build = {
bat '''
set "PATH=%PATH%;C:\\Program Files\\TortoiseSVN\\bin\\;c:\\bin\\jdk\\bin;c:\\bin\\nsis\\;c:\\bin\\git\\bin;c:\\Program Files\\Git\\bin"
cd /d "%OM_RELEASES%" || exit /b 1
set MSYSTEM=%OMDEV_MSYSTEM%
"%OMDEV%\\tools\\msys\\usr\\bin\\sh" --login -c "time %OM_DIR_MSYS%/OMSetup/BuildWindowsRelease.sh %OM_SSHUSER% %MAKETHREADS% 64bit %OM_GIT_BRANCH%"
'''
}
if (params.TOKEN_CREDENTIAL) {
withCredentials([string(credentialsId: params.TOKEN_CREDENTIAL, variable: 'TOKEN_PW')]) {
build()
}
} else {
build()
}
}
}
}
}
}