-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJenkinsfile_parameterized
244 lines (232 loc) · 10.2 KB
/
Jenkinsfile_parameterized
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
podTemplate(
//idleMinutes : 30,
podRetention : onFailure(),
activeDeadlineSeconds : 3600,
containers: [
containerTemplate(
name: 'dtk-rpm-builder',
image: 'docker-production.packages.idmod.org/idm/dtk-rpm-builder:0.1',
command: 'sleep',
args: '30d'
)
]) {
properties([
parameters([
gitParameter(branch: '',
branchFilter: 'origin/(.*)',
defaultValue: 'main',
description: '',
name: 'BRANCH',
quickFilterEnabled: false,
selectedValue: 'NONE',
sortMode: 'NONE',
tagFilter: '*',
type: 'PT_BRANCH'),
gitParameter(branch: '',
branchFilter: '.*',
defaultValue: '-1',
name: 'PR',
quickFilterEnabled: false,
selectedValue: 'NONE',
sortMode: 'DESCENDING_SMART',
tagFilter: '*',
type: 'PT_PULL_REQUEST'),
choice(choices: ['Code', 'Production', 'Staging'], name: 'hiv_environment'),
string(defaultValue: '-1', name: 'emod_hiv_version'),
choice(choices: ['Production', 'Staging'], name: 'emod_hiv_environment'),
string(defaultValue: '-1', name: 'emodpy_version'),
choice(choices: ['Production', 'Staging'], name: 'emodpy_environment'),
string(defaultValue: '-1', name: 'emodapi_version'),
choice(choices: ['Production', 'Staging'], name: 'emodapi_environment'),
booleanParam(defaultValue: false, name: 'Run_Examples'),
booleanParam(defaultValue: false, name: 'dev_package'),
string(name:'filter', defaultValue: 'test_*', description: 'Simulation tests filter i.e. sim_test*, sim_test_abc* ')
])])
node(POD_LABEL) {
container('dtk-rpm-builder'){
def build_ok = true
def devInstall = ""
if (params.dev_package) {
devInstall = "--pre"
echo "dev_package is enabled ${devInstall}"
}
stage('Cleanup Workspace') {
// sleep(time:30,unit:"MINUTES")
// sh """
// sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-Linux-*
// sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-Linux-*
// dnf module -y install python39
// python3 --version
// """
cleanWs()
echo "Cleaned Up Workspace For Project"
echo "${params.BRANCH}"
}
stage('Code Checkout') {
if (params.PR.toString() != '-1') {
echo "I execute on the pull request ${params.PR}"
checkout([$class: 'GitSCM',
branches: [[name: "pr/${params.PR}/head"]],
doGenerateSubmoduleConfigurations: false,
extensions: [],
gitTool: 'Default',
submoduleCfg: [],
userRemoteConfigs: [[refspec: '+refs/pull/*:refs/remotes/origin/pr/*', credentialsId: '704061ca-54ca-4aec-b5ce-ddc7e9eab0f2', url: '[email protected]:InstituteforDiseaseModeling/emodpy-hiv.git']]])
} else {
echo "I execute on the ${params.BRANCH} branch"
git branch: "${params.BRANCH}",
credentialsId: '704061ca-54ca-4aec-b5ce-ddc7e9eab0f2',
url: '[email protected]:InstituteforDiseaseModeling/emodpy-hiv.git'
}
}
stage('Prepare') {
//sh 'yum install -y dnf'
//sh 'dnf install -y python39-devel'
sh 'python --version'
sh 'python3 --version'
sh 'pip3 --version'
sh 'python3 -m pip install --upgrade pip'
//sh 'python3 -m pip install --upgrade wheel'
sh "pip3 install wheel"
sh 'python3 -m pip install --upgrade setuptools'
sh 'pip3 freeze'
}
stage('Build') {
sh 'pwd'
sh 'ls -a'
if (params.hiv_environment == 'Code') {
//sh 'python3 -m build'
sh 'python3 setup.py bdist_wheel'
}
}
stage('Install') {
def curDate = sh(returnStdout: true, script: "date").trim()
echo "The current date is ${curDate}"
echo "${devInstall}"
if (params.hiv_environment == 'Staging') {
echo "I am installing emodpy-hiv from Staging"
withCredentials([string(credentialsId: 'idm_bamboo_user', variable: 'user'), string(credentialsId: 'idm_bamboo_user_password', variable: 'password')]) {
sh 'pip3 install emodpy-hiv --index-url=https://$user:[email protected]/api/pypi/pypi-staging/simple $devInstall'
}
} else if (params.hiv_environment == 'Production'){
echo "I am installing emodpy-hiv from Production"
sh 'pip3 install emodpy-hiv --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple --pre'
} else {
echo "I am installing emodpy-hiv from wheel file built from code"
def wheelFile = sh(returnStdout: true, script: "find ./dist -name '*.whl'").toString().trim()
//def wheelFile = sh(returnStdout: true, script: "python3 ./.github/scripts/get_wheel_filename.py --package-file setup.py").toString().trim()
echo "This is the package file: ${wheelFile}"
sh "pip3 install $wheelFile --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple $devInstall"
}
if (params.emod_hiv_version != '-1') {
def emod_version = params.emod_hiv_version
echo "I am re-installing emodhiv==${emod_version} from ${params.emod_hiv_environment}"
if (params.emod_hiv_environment == 'Staging') {
withCredentials([string(credentialsId: 'idm_bamboo_user', variable: 'user'), string(credentialsId: 'idm_bamboo_user_password', variable: 'password')]) {
sh "pip3 install emod-hiv==${emod_version} --index-url=https://$user:[email protected]/api/pypi/pypi-staging/simple --force-reinstall --no-cache-dir"}
} else {
sh "pip3 install emod-hiv==${emod_version} --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple --force-reinstall --no-cache-dir"
}
}
if (params.emodpy_version != '-1') {
def version = params.emodpy_version
echo "I am re-installing emodpy==${version} from ${params.emodpy_environment}"
if (params.emodpy_environment == 'Staging') {
withCredentials([string(credentialsId: 'idm_bamboo_user', variable: 'user'), string(credentialsId: 'idm_bamboo_user_password', variable: 'password')]) {
sh "pip3 install emodpy==${version} --index-url=https://$user:[email protected]/api/pypi/pypi-staging/simple --force-reinstall --no-cache-dir"
}
} else {
sh "pip3 install emodpy==${version} --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple --force-reinstall --no-cache-dir"
}
}
if (params.emodapi_version != '-1') {
def api_version = params.emodapi_version
echo "I am re-installing emodapi==${api_version} from ${params.emodapi_environment}"
if (params.emodapi_environment == 'Staging') {
withCredentials([string(credentialsId: 'idm_bamboo_user', variable: 'user'), string(credentialsId: 'idm_bamboo_user_password', variable: 'password')]) {
sh "pip3 install emod-api==${api_version} --index-url=https://$user:[email protected]/api/pypi/pypi-staging/simple --force-reinstall --no-cache-dir"
}
} else {
sh "pip3 install emod-api==${api_version} --index-url=https://packages.idmod.org/api/pypi/pypi-production/simple --force-reinstall --no-cache-dir"
}
}
}
stage('Test Install')
{
sh "pip3 install unittest-xml-reporting"
sh "pip3 install dataclasses"
sh "pip3 install keyrings.alt"
}
stage('Login')
{
//sh "pip3 install dataclasses"
sh 'pip3 install keyrings.alt'
sh "pip3 freeze"
withCredentials([usernamePassword(credentialsId: 'comps_jenkins_user', usernameVariable: 'COMPS_USERNAME', passwordVariable: 'COMPS_PASSWORD'),
usernamePassword(credentialsId: 'comps2_jenkins_user', usernameVariable: 'COMPS2_USERNAME', passwordVariable: 'COMPS2_PASSWORD')]) {
dir('tests') {
sh '''
pip3 install 'urllib3<2.0' --force-reinstall
'''
sh 'python3 create_auth_token_args.py --comps_url https://comps2.idmod.org --username $COMPS2_USERNAME --password $COMPS2_PASSWORD'
sh 'python3 create_auth_token_args.py --comps_url https://comps.idmod.org --username $COMPS_USERNAME --password $COMPS_PASSWORD'
}
}
}
try{
stage('Unit Test') {
echo "Running Unit test Tests"
dir('tests/unittests') {
sh 'python3 -m xmlrunner discover'
junit '*.xml'
}
}
} catch(e) {
build_ok = false
echo e.toString()
}
try{
stage('Run Sim Tests') {
echo "Running Simulation Tests"
dir('tests/sim_tests') {
script {
echo "Running tests with filter: ${params.filter}"
// Find files that meet the filter criteria
def filesToTest = sh(script: "find . -type f -name '${params.filter}'", returnStdout: true).trim().split('\n')
// Execute the test command on each file
filesToTest.each { file ->
sh "echo 'Executing tests on file: $file'"
sh "python3 $file"
}
}
}
}
} catch(e) {
build_ok = false
echo e.toString()
}
if(params.Run_Examples){
try{
stage('Run Examples') {
echo "Running examples"
dir('examples') {
sh 'pip3 install snakemake'
sh 'snakemake --cores=10 --config python_version=python3'
}
}
}catch(e) {
build_ok = false
echo e.toString()
}
finally {
archiveArtifacts artifacts: 'examples/.snakemake/log/*.snakemake.log', fingerprint: true
}
}
if(build_ok) {
currentBuild.result = "SUCCESS"
} else {
currentBuild.result = "FAILURE"
}
}
}
}