-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJenkinsfile
253 lines (224 loc) · 7.3 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
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
#!groovy
@Library('PACE-shared-lib') _
properties([
parameters([
string(
name: 'BRANCH',
defaultValue: '',
description: 'Branch to build',
trim: true
),
string(
name: 'PYTHON_VERSION',
defaultValue: '3.8',
description: 'Version of python to run the build with.',
trim: true
),
string(
name: 'MATLAB_VERSION',
defaultValue: '2021b',
description: 'Version of Matlab to run the build with.',
trim: true
),
string(
name: 'GCC_VERSION',
defaultValue: '11',
description: 'Version of gcc to load',
trim: true
)
])
])
def get_agent(String jobname) {
if (jobname.contains('linux')) {
return "rocky8"
} else if (jobname.contains('windows')) {
return "icdpacewin"
} else {
return ''
}
}
def get_github_token() {
withCredentials([string(credentialsId: 'GitHub_API_Token', variable: 'github_token')]) {
return "${github_token}"
}
}
def name_conda_env(String python_version) {
def env_name = "py" + python_version.replace(".","")
return env_name
}
pipeline {
agent {
label get_agent(env.JOB_BASE_NAME)
}
environment {
ENV_NAME = name_conda_env(env.PYTHON_VERSION)
}
stages {
stage('Notify') {
steps {
post_github_status("pending", "The build is running")
}
}
stage('Display-Environment-Variables') {
steps {
script {
if (isUnix()) {
sh 'env'
}
else {
powershell 'Get-ChildItem Env:'
}
}
}
}
stage("Build-Pace-Python") {
steps {
script {
if (isUnix()) {
sh '''
module purge
module load matlab/\$MATLAB_VERSION
module load cmake
module load conda
module load gcc/\$GCC_VERSION
conda create -n \$ENV_NAME -c conda-forge python=\$PYTHON_VERSION -y
conda activate \$ENV_NAME
conda install -c conda-forge setuptools
python setup.py bdist_wheel
'''
archiveArtifacts artifacts: 'dist/*whl'
}
else {
powershell(script:'''
conda create --prefix ./\$env:ENV_NAME -c conda-forge python=\$env:PYTHON_VERSION -y
Import-Module "C:/ProgramData/miniconda3/shell/condabin/Conda.psm1"
Enter-CondaEnvironment ./\$env:ENV_NAME
conda env list
conda install -c conda-forge setuptools
python setup.py bdist_wheel -DMatlab_ROOT_DIR=/opt/modules-common/software/MATLAB/R\$env:MATLAB_VERSION
''', label: "setup and build")
archiveArtifacts artifacts: 'dist/*whl'
}
}
}
}
stage("Build-Installer") {
steps {
script {
if (isUnix()) {
sh '''
module load matlab/\$MATLAB_VERSION
matlab -nodesktop -r "try, cd('installer'), run('make_package.m'), catch ME, fprintf('%s: %s\\n', ME.identifier, ME.message), end, exit"
test -f "./installer/pace_python_installer/MyAppInstaller.install"
'''
}
else {
powershell '''
Try {
$MATLAB_REG = Get-ItemProperty "Registry::HKEY_LOCAL_MACHINE\\SOFTWARE\\Mathworks\\MATLAB\\9.9" -ErrorAction Stop
$MATLAB_EXE = $MATLAB_REG.MATLABROOT + "\\bin\\matlab.exe"
} Catch {
Write-Output "Could not find Matlab R2020b folder. Using default Matlab"
$MATLAB_EXE = "matlab.exe"
}
$mstr = "try, cd('installer'), run('make_package.m'), catch ME, fprintf('%s: %s\\n', ME.identifier, ME.message), end, exit"
Invoke-Expression "& `'$MATLAB_EXE`' -nosplash -nodesktop -wait -r `"$mstr`""
if (!(Test-Path -Path "./installer/pace_python_installer/MyAppInstaller.exe")) {
throw "Installer creation error. No installer executable found at ./install/pace_python_installer/"
}
'''
}
}
}
}
stage("Get-Pace-Python-Demo") {
steps {
dir('demo') {
checkout([
$class: 'GitSCM',
branches: [[name: "refs/heads/main"]],
extensions: [[$class: 'WipeWorkspace']],
userRemoteConfigs: [[url: 'https://github.com/pace-neutrons/pace-python-demo']]
])
}
}
}
stage("Run-Pace-Python-Tests") {
environment {
LD_LIBRARY_PATH = "/opt/modules-common/software/MATLAB/R${MATLAB_VERSION}/runtime/glnxa64:/opt/modules-common/software/MATLAB/R${MATLAB_VERSION}/bin/glnxa64"
LD_PRELOAD = "/opt/modules-common/software/MATLAB/R${MATLAB_VERSION}/sys/os/glnxa64/libiomp5.so"
}
steps {
script {
if (isUnix()) {
sh '''
module purge
module load conda
module load matlab/\$MATLAB_VERSION
eval "$(/opt/conda/bin/conda shell.bash hook)"
conda env remove -n \$ENV_NAME
conda create -n \$ENV_NAME -c conda-forge python=\$PYTHON_VERSION -y
conda activate \$ENV_NAME
pip install numpy scipy euphonic --no-input
export MKL_NUM_THREADS=1
python -m pip install brille
python -m pip install $(find dist -name "*whl"|tail -n1)
timeout --signal 15 6m python test/run_test.py -v
test -f success
'''
}
else {
powershell(script:'''
conda env remove --prefix ./\$env:ENV_NAME
conda create --prefix ./\$env:ENV_NAME -c conda-forge python=\$env:PYTHON_VERSION -y
Import-Module "C:/ProgramData/miniconda3/shell/condabin/Conda.psm1"
Enter-CondaEnvironment ./\$env:ENV_NAME
conda install -c conda-forge scipy euphonic -y
python -m pip install brille
python -m pip install "dist/$(Get-ChildItem 'dist/*.whl' -name)"
python test/run_test.py -v
''', label: "Setup and run tests")
}
}
}
}
stage("Push release") {
environment {
GITHUB_TOKEN = get_github_token()
}
steps {
script {
if (env.BRANCH.startsWith("refs/tags")) {
if (isUnix()) {
sh '''
module load conda
conda activate \$ENV_NAME
pip install requests pyyaml
python release.py --github --notest
'''
}
else {
powershell(script: '''
Import-Module "C:/ProgramData/miniconda3/shell/condabin/Conda.psm1"
Enter-CondaEnvironment ./\$env:ENV_NAME
python -m pip install requests pyyaml
python release.py --github --notest
''', label: "Create-Github-Release")
}
}
}
}
}
}
post {
success {
post_github_status("success", "The build succeeded")
}
unsuccessful {
post_github_status("failure", "The build failed")
}
cleanup {
deleteDir()
}
}
}