forked from maxlaverse/kubernetes-cli-plugin
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Jenkinsfile
112 lines (101 loc) · 3.29 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
// Java versions to test against
String[] unitTestJdkVersions = [17, 21]
String integrationJdkVersions = 17
// Platform to test for
String[] platforms = [
'windows',
'linux',
]
// Kubectl versions to test against
String[] kubectlVersions = [
'1.26.14',
'1.27.11',
'1.28.7',
'1.29.2',
]
// Not sure what this does yet
def buildNumber = BUILD_NUMBER as int; if (buildNumber > 1) milestone(buildNumber - 1); milestone(buildNumber) // JENKINS-43353 / JENKINS-58625
properties([
durabilityHint('PERFORMANCE_OPTIMIZED'),
buildDiscarder(logRotator(numToKeepStr: '3')),
])
// Generates a build block that can later be run in parallel
// for which the kubectl version, platform and java version
// can be specified
def integrationTest(platform, jdk, kubectlVersion) {
node(platform) {
timeout(15) {
withEnv(["PATH+KUBECTL=${env.WORKSPACE}/.bin", "KUBECTL_VERSION=v${kubectlVersion}"]){
stage('checkout') {
checkout scm
}
stage('preparation') {
retry(5) {
downloadKubectl(kubectlVersion)
}
}
stage('tests') {
infra.runWithJava('mvn clean -Dgroups=org.jenkinsci.plugins.kubernetes.cli.KubectlIntegrationTest test', jdk)
}
}
}
}
}
def unitTest(platform, jdk) {
node(platform) {
timeout(15) {
stage('checkout') {
checkout scm
}
stage('tests') {
infra.runWithJava('mvn clean -Dgroups="! org.jenkinsci.plugins.kubernetes.cli.KubectlIntegrationTest" test spotbugs:check', jdk)
}
// stage('coverage') {
// infra.runWithJava('mvn jacoco:report coveralls:report')
// }
}
}
}
// Generates a script block to download kubectl
def downloadKubectl(kubectlVersion){
if (isUnix()) {
sh """
mkdir -p .bin
cd .bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v${kubectlVersion}/bin/linux/amd64/kubectl
chmod +x kubectl
kubectl version --client
"""
}else{
bat """
mkdir -p .bin
cd .bin
curl -LO https://storage.googleapis.com/kubernetes-release/release/v${kubectlVersion}/bin/windows/amd64/kubectl.exe
kubectl.exe version --client
"""
}
}
// Build a step for all combinations we want to test for
def stepsForParallel = [:]
for (int i = 0; i < kubectlVersions.size(); i++) {
def kubectlVersion = kubectlVersions[i]
for (int j = 0; j < platforms.size(); j++) {
def platform = platforms[j]
def stepName = "integration/${platform}/v${kubectlVersion}"
stepsForParallel[stepName] = { ->
integrationTest(platform, integrationJdkVersions, kubectlVersion)
}
}
}
for (int j = 0; j < platforms.size(); j++) {
def platform = platforms[j]
for (int k = 0; k < unitTestJdkVersions.size(); k++) {
def jdkVersion = unitTestJdkVersions[k]
def stepName = "unit/${platform}/${jdkVersion}"
stepsForParallel[stepName] = { ->
unitTest(platform, jdkVersion)
}
}
}
// Run tests in parallel
parallel stepsForParallel