Repository navigation
Expand file tree
/
Copy pathJenkinsfile.BuildWindowsRelease
More file actions
192 lines (189 loc) · 10.3 KB
/
Copy pathJenkinsfile.BuildWindowsRelease
File metadata and controls
192 lines (189 loc) · 10.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
// Jenkins pipeline that builds the OpenModelica Windows release/nightly installer.
// 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.
//
// 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.
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 c:\dev layout, not the workspace
skipDefaultCheckout()
}
parameters {
string(name: 'GIT_BRANCH', defaultValue: 'master', description: 'OpenModelica tag or branch to build, master for the nightly build, or #NUMBER (for instance #14016) to build that pull request')
booleanParam(name: 'FORCE_BUILD', defaultValue: false, description: 'Delete the previous builds in c:\\dev\\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 {
OMDEV = 'C:\\OMDevUCRT'
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.trim().matches('#[0-9]+') ? 'PR_' + params.GIT_BRANCH.trim().substring(1) + '_experimental' : params.GIT_BRANCH.trim()}"
OM_REQUIRE_SIGNING = "${params.OM_REQUIRE_SIGNING ? 'yes' : ''}"
OM_ENABLE_ENCRYPTION = "${params.OM_ENABLE_ENCRYPTION ? 'yes' : ''}"
// BuildWindowsRelease.sh builds the encryption release in c:\dev\e\OM64bit
OM_DIR = "${params.OM_ENABLE_ENCRYPTION ? 'c:\\dev\\e\\OM64bit' : 'c:\\dev\\OM64bit'}"
OM_DIR_MSYS = "${params.OM_ENABLE_ENCRYPTION ? '/c/dev/e/OM64bit' : '/c/dev/OM64bit'}"
OM_RELEASES = "${params.OM_ENABLE_ENCRYPTION ? 'c:\\dev\\OpenModelica_releases\\e' : 'c:\\dev\\OpenModelica_releases'}"
}
stages {
stage('Prepare') {
steps {
script {
if (params.GIT_BRANCH.trim().matches('#[0-9]+')) {
currentBuild.displayName = "#${env.BUILD_NUMBER} PR ${params.GIT_BRANCH.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 OMDEV: %OMDEV%
if not exist "%OMDEV%" (
cd /d c:\\ || exit /b 1
git clone https://gitlab.liu.se/OpenModelica/OMDevUCRT.git OMDevUCRT || exit /b 1
cd /d "%OMDEV%" || exit /b 1
git checkout master || exit /b 1
call SETUP_OMDEV.bat || exit /b 1
)
if not exist c:\\dev\\ md c:\\dev\\
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 checkout master || 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 adrpo %MAKETHREADS% 64bit %OM_GIT_BRANCH%"
'''
}
if (params.TOKEN_CREDENTIAL) {
withCredentials([string(credentialsId: params.TOKEN_CREDENTIAL, variable: 'TOKEN_PW')]) {
build()
}
} else {
build()
}
}
}
}
}
}