Skip to content

Commit 53d75aa

Browse files
committed
Parallel CI
1 parent 45d9da3 commit 53d75aa

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

Jenkinsfile

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,30 @@ properties([
33
durabilityHint('PERFORMANCE_OPTIMIZED'),
44
buildDiscarder(logRotator(numToKeepStr: '5')),
55
])
6-
parallel kind: {
7-
node('docker') {
8-
timeout(90) {
9-
checkout scm
10-
withEnv(["WSTMP=${pwd tmp: true}"]) {
6+
7+
def splits
8+
node('alpine') {
9+
checkout scm
10+
splits = splitTests parallelism: count(2), generateInclusions: true, estimateTestsFromFiles: true
11+
}
12+
def branches = [:]
13+
14+
for (int i = 1; i < splits.size() + 1; i++) {
15+
def num = i
16+
def split = splits[num]
17+
branches["kind-${num}"] = {
18+
node('docker') {
19+
timeout(90) {
20+
checkout scm
1121
try {
12-
sh 'bash kind.sh'
13-
dir (WSTMP) {
22+
writeFile file: (split.includes ? "$WORKSPACE_TMP/includes.txt" : "$WORKSPACE_TMP/excludes.txt"), text: split.list.join("\n")
23+
writeFile file: (split.includes ? "$WORKSPACE_TMP/excludes.txt" : "$WORKSPACE_TMP/includes.txt"), text: ''
24+
sh 'kind.sh -Dsurefire.includesFile="$WORKSPACE_TMP/includes.txt -Dsurefire.excludesFile="$WORKSPACE_TMP/excludes.txt"'
25+
dir (env.WORKSPACE_TMP) {
1426
junit 'surefire-reports/*.xml'
1527
}
1628
} finally {
17-
dir (WSTMP) {
29+
dir (env.WORKSPACE_TMP) {
1830
if (fileExists('kindlogs/docker-info.txt')) {
1931
archiveArtifacts 'kindlogs/'
2032
}
@@ -23,7 +35,8 @@ parallel kind: {
2335
}
2436
}
2537
}
26-
}, jdk11: {
38+
}
39+
branches['jdk11'] = {
2740
node('maven-11') {
2841
timeout(60) {
2942
checkout scm
@@ -32,5 +45,6 @@ parallel kind: {
3245
junit 'target/surefire-reports/*.xml'
3346
}
3447
}
35-
}, failFast: true
48+
}
49+
parallel branches, failFast: true
3650
infra.maybePublishIncrementals()

kind.sh

100644100755
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -euxo pipefail
33

4-
export PATH=$WSTMP:$PATH
5-
if [ \! -x $WSTMP/kind ]
4+
export PATH=$WORKSPACE_TMP:$PATH
5+
if [ \! -x "$WORKSPACE_TMP/kind" ]
66
then
7-
curl -sLo $WSTMP/kind https://github.com/kubernetes-sigs/kind/releases/download/v0.17.0/kind-$(uname | tr '[:upper:]' '[:lower:]')-amd64
8-
chmod +x $WSTMP/kind
7+
curl -sLo "$WORKSPACE_TMP/kind" https://github.com/kubernetes-sigs/kind/releases/download/v0.17.0/kind-$(uname | tr '[:upper:]' '[:lower:]')-amd64
8+
chmod +x "$WORKSPACE_TMP/kind"
99
fi
10-
if [ \! -x $WSTMP/kubectl ]
10+
if [ \! -x "$WORKSPACE_TMP/kubectl" ]
1111
then
12-
curl -sLo $WSTMP/kubectl https://storage.googleapis.com/kubernetes-release/release/v1.25.4/bin/$(uname | tr '[:upper:]' '[:lower:]')/amd64/kubectl
13-
chmod +x $WSTMP/kubectl
12+
curl -sLo "$WORKSPACE_TMP/kubectl" https://storage.googleapis.com/kubernetes-release/release/v1.25.4/bin/$(uname | tr '[:upper:]' '[:lower:]')/amd64/kubectl
13+
chmod +x "$WORKSPACE_TMP/kubectl"
1414
fi
1515

1616
export cluster=ci$RANDOM
17-
export KUBECONFIG=$WSTMP/kubeconfig-$cluster
17+
export KUBECONFIG="$WORKSPACE_TMP/kubeconfig-$cluster"
1818
kind create cluster --name $cluster --wait 5m
1919
function cleanup() {
20-
kind export logs --name $cluster $WSTMP/kindlogs || :
20+
kind export logs --name $cluster "$WORKSPACE_TMP/kindlogs" || :
2121
kind delete cluster --name $cluster || :
22-
rm $KUBECONFIG
22+
rm "$KUBECONFIG"
2323
}
2424
trap cleanup EXIT
2525
kubectl cluster-info
@@ -29,10 +29,10 @@ PRE_LOAD_IMAGES+=($(grep -e image: test-in-k8s.yaml | cut -d ':' -f 2- | xargs))
2929
PRE_LOAD_IMAGES+=($(grep -h --include="*.groovy" -e "^\s*image: .*$" -R src/test/resources | sed -e "s/^[[:space:]]*image: //" | sort | uniq | grep -v "windows" | grep -v "nonexistent" | grep -v "invalid" | xargs))
3030
for image in "${PRE_LOAD_IMAGES[@]}"
3131
do
32-
docker pull $image
33-
kind load docker-image $image --name $cluster
32+
docker pull "$image"
33+
kind load docker-image "$image" --name $cluster
3434
done
3535

36-
bash test-in-k8s.sh
37-
rm -rf $WSTMP/surefire-reports
38-
kubectl cp jenkins:/checkout/target/surefire-reports $WSTMP/surefire-reports
36+
test-in-k8s.sh "$@"
37+
rm -rf "$WORKSPACE_TMP/surefire-reports"
38+
kubectl cp jenkins:/checkout/target/surefire-reports "$WORKSPACE_TMP/surefire-reports"

test-in-k8s.sh

100644100755
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
set -euxo pipefail
33
function cleanup() {
44
kubectl describe pod
@@ -9,21 +9,15 @@ kubectl get ns kubernetes-plugin-test || kubectl create ns kubernetes-plugin-tes
99
kubectl get ns kubernetes-plugin-test-overridden-namespace || kubectl create ns kubernetes-plugin-test-overridden-namespace
1010
kubectl config set-context --current --namespace=kubernetes-plugin-test
1111
port_offset=$RANDOM
12-
http_port=$((2000 + $port_offset))
13-
tcp_port=$((2001 + $port_offset))
12+
http_port=$((2000 + port_offset))
13+
tcp_port=$((2001 + port_offset))
1414
kubectl delete --ignore-not-found --now pod jenkins
1515
sed "s/@HTTP_PORT@/$http_port/g; s/@TCP_PORT@/$tcp_port/g" < test-in-k8s.yaml | kubectl apply -f -
1616
kubectl wait --for=condition=Ready --timeout=15m pod/jenkins
1717
kubectl exec jenkins -- mkdir /checkout
1818
kubectl cp pom.xml jenkins:/checkout/pom.xml
1919
kubectl cp .mvn jenkins:/checkout/.mvn
2020
kubectl cp src jenkins:/checkout/src
21-
if [ -v TEST ]
22-
then
23-
args="-Dtest=$TEST test"
24-
else
25-
args=verify
26-
fi
2721
kubectl exec jenkins -- \
2822
mvn \
2923
-B \
@@ -34,5 +28,6 @@ kubectl exec jenkins -- \
3428
-DslaveAgentPort=$tcp_port \
3529
-Djenkins.host.address=jenkins.kubernetes-plugin-test.svc.cluster.local \
3630
-Dmaven.test.failure.ignore \
37-
$args
31+
verify
32+
"$@"
3833
kubectl exec jenkins -- sh -c 'fgrep skipped /checkout/target/surefire-reports/*.xml' || :

0 commit comments

Comments
 (0)