-
Notifications
You must be signed in to change notification settings - Fork 34
/
Jenkinsfile
193 lines (166 loc) · 7.04 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
#!groovy
def BN = (BRANCH_NAME == 'master' || BRANCH_NAME.startsWith('releases/')) ? BRANCH_NAME : 'releases/2024-12'
@groovy.transform.Field
static final String[] WF_TESTS_PYTHON_ENVS = [
'bundled',
'env_py36_pa5.yml',
'env_py38_pa7.yml',
'env_py39_kn47.yml',
]
@groovy.transform.Field
static final String DEFAULT_WF_TESTS_PYTHON_ENV = 'bundled'
@groovy.transform.Field
static final List<String> PYTEST_PYTHON_ENVS = ['env_py38_legacy', 'env_py38', 'env_py39', 'env_py311']
library "knime-pipeline@$BN"
def baseBranch = (BN == KNIMEConstants.NEXT_RELEASE_BRANCH ? 'master' : BN.replace('releases/', ''))
/** Return parameters to select python environment to run workflowtests with */
def getWFTestsPythonEnvParameters() {
def pythonParams = []
for (c in WF_TESTS_PYTHON_ENVS) {
pythonParams += booleanParam(
defaultValue: c == DEFAULT_WF_TESTS_PYTHON_ENV || BRANCH_NAME.startsWith('releases/'),
description: "Run workflowtests with Python environment ${c}",
name: c
)
}
return pythonParams
}
properties([
pipelineTriggers([
upstream("knime-conda-channels/${BRANCH_NAME.replaceAll('/', '%2F')}, " +
"knime-python-nodes-testing/${BRANCH_NAME.replaceAll('/', '%2F')}, " +
"knime-core-ui/${BRANCH_NAME.replaceAll('/', '%2F')}")
]),
parameters(
workflowTests.getConfigurationsAsParameters() + \
getWFTestsPythonEnvParameters() + \
booleanParam(defaultValue: false, description: 'Upload conda package despite tests being unstable or being on master.', name: 'UPLOAD_ANYWAY')
),
buildDiscarder(logRotator(numToKeepStr: '5')),
disableConcurrentBuilds()
])
try {
node('maven && java17 && ubuntu22.04 && workflow-tests') {
knimetools.defaultTychoBuild(updateSiteProject: 'org.knime.update.python')
}
def parallelConfigs = [:]
for (env in WF_TESTS_PYTHON_ENVS) {
if (params[env]) {
// need to create a deep copy here, otherwise Jenkins will use
// the last selected option for everything
String environmentFile = new String(env)
parallelConfigs["${environmentFile}"] = {
runPython3MultiversionWorkflowTestConfig(environmentFile, baseBranch)
}
}
}
parallel(parallelConfigs)
node('ubuntu22.04 && workflow-tests && java17') {
stage('Clone') {
env.lastStage = env.STAGE_NAME
checkout scm
}
for (pyEnv in PYTEST_PYTHON_ENVS) {
stage("Run pytest for ${pyEnv}") {
env.lastStage = env.STAGE_NAME
String envPath = "${env.WORKSPACE}/pytest-envs/${pyEnv}"
String envYml = "${env.WORKSPACE}/pytest-envs/${pyEnv}.yml"
sh(label: 'create conda env', script: """
micromamba create -p ${envPath} -f ${envYml}
""")
sh(label: 'run pytest', script: """
${envPath}/bin/coverage run -m pytest --junit-xml=pytest_results.xml || true
# create a separate coverage.xml file for each module
for d in org.knime.python3*/ ; do
${envPath}/bin/coverage xml -o "\${d}coverage-${pyEnv}.xml" --include "*\$d**/*.py" || true
# delete mention of module name in coverage.xml
if [ -f "\${d}coverage-${pyEnv}.xml" ]; then
sed -i "s|\$d||g" "\${d}coverage-${pyEnv}.xml"
fi
done
""")
junit 'pytest_results.xml'
stash(name: "${pyEnv}", includes: "**/coverage-${pyEnv}.xml")
}
}
stage('Build and Deploy knime-extension ') {
env.lastStage = env.STAGE_NAME
String envName = "test_knime_extension"
String recipePath = "${env.WORKSPACE}/knime-extension/recipe"
String prefixPath = "${env.WORKSPACE}/${envName}"
String[] packageNames = [
"conda-build",
"anaconda-client"
]
condaHelpers.createCondaEnv(prefixPath: prefixPath, packageNames: packageNames)
sh(
label: "Collect Files",
script: """#!/bin/sh
cd knime-extension
micromamba run -p ${prefixPath} python ${env.WORKSPACE}/knime-extension/collect_files.py
"""
)
// Only upload if on master and tests pass
def upload = params.FORCE_UPLOAD_PACKAGE || (BN == 'master' && currentBuild.result != 'UNSTABLE')
condaHelpers.buildCondaPackage(recipePath, prefixPath, upload)
}
stage('Sonarqube analysis') {
env.lastStage = env.STAGE_NAME
env.SONAR_ENV = "Sonarcloud"
configs = workflowTests.ALL_CONFIGURATIONS + PYTEST_PYTHON_ENVS
echo "running sonar on ${configs}"
workflowTests.runSonar(configs)
}
owasp.sendNodeJSSBOMs(readMavenPom(file: 'pom.xml').properties['revision'])
}
} catch (ex) {
currentBuild.result = 'FAILURE'
throw ex
} finally {
notifications.notifyBuild(currentBuild.result)
}
def runPython3MultiversionWorkflowTestConfig(String environmentFile, String baseBranch) {
withEnv([ "KNIME_WORKFLOWTEST_PYTHON_ENVIRONMENT=${environmentFile}" ]) {
stage("Workflowtests with Python: ${environmentFile}") {
workflowTests.runTests(
dependencies: [
repositories: [
'knime-chemistry',
'knime-database',
'knime-office365',
'knime-datageneration',
'knime-distance',
'knime-ensembles',
'knime-filehandling',
'knime-jep',
'knime-jfreechart',
'knime-js-base',
'knime-kerberos',
'knime-python',
'knime-core-columnar',
'knime-testing-internal',
'knime-xml',
'knime-python-legacy',
'knime-conda',
'knime-python-nodes-testing',
'knime-base-views',
'knime-scripting-editor',
'knime-gateway',
'knime-credentials-base',
'knime-google',
'knime-cloud',
'knime-buildworkflows',
'knime-productivity-oss',
'knime-reporting',
'knime-cef',
],
ius: [
'org.knime.features.chem.types.feature.group',
'org.knime.features.core.columnar.feature.group'
]
],
)
}
}
}
/* vim: set shiftwidth=4 expandtab smarttab: */