Skip to content

Commit 9795105

Browse files
authored
Merge branch 'master' into JENKINS-70392-tests-followup
2 parents b183c3d + 5891888 commit 9795105

File tree

4 files changed

+68
-52
lines changed

4 files changed

+68
-52
lines changed

Jenkinsfile

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,55 @@ 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}"]) {
11-
try {
12-
sh 'bash kind.sh'
13-
dir (WSTMP) {
14-
junit 'surefire-reports/*.xml'
15-
}
16-
} finally {
17-
dir (WSTMP) {
18-
if (fileExists('kindlogs/docker-info.txt')) {
19-
archiveArtifacts 'kindlogs/'
6+
7+
def splits
8+
stage('Determine splits') {
9+
node('linux') {
10+
checkout scm
11+
splits = splitTests parallelism: count(2), generateInclusions: true, estimateTestsFromFiles: true
12+
}
13+
}
14+
stage('Tests') {
15+
def branches = [:]
16+
branches['failFast'] = true
17+
18+
for (int i = 0; i < splits.size(); i++) {
19+
def num = i
20+
def split = splits[num]
21+
def index = num + 1
22+
branches["kind-${index}"] = {
23+
node('docker') {
24+
timeout(90) {
25+
checkout scm
26+
try {
27+
writeFile file: (split.includes ? "$WORKSPACE_TMP/includes.txt" : "$WORKSPACE_TMP/excludes.txt"), text: split.list.join("\n")
28+
writeFile file: (split.includes ? "$WORKSPACE_TMP/excludes.txt" : "$WORKSPACE_TMP/includes.txt"), text: ''
29+
sh './kind.sh -Dsurefire.includesFile="$WORKSPACE_TMP/includes.txt" -Dsurefire.excludesFile="$WORKSPACE_TMP/excludes.txt"'
30+
dir(env.WORKSPACE_TMP) {
31+
junit 'surefire-reports/*.xml'
32+
}
33+
} finally {
34+
dir(env.WORKSPACE_TMP) {
35+
if (fileExists('kindlogs/docker-info.txt')) {
36+
archiveArtifacts 'kindlogs/'
37+
}
2038
}
2139
}
2240
}
2341
}
2442
}
2543
}
26-
}, jdk11: {
27-
node('maven-11') {
28-
timeout(60) {
29-
checkout scm
30-
sh 'mvn -B -ntp -Dset.changelist -Dmaven.test.failure.ignore clean install'
31-
infra.prepareToPublishIncrementals()
32-
junit 'target/surefire-reports/*.xml'
44+
branches['jdk11'] = {
45+
node('maven-11') {
46+
timeout(60) {
47+
checkout scm
48+
sh 'mvn -B -ntp -Dset.changelist -Dmaven.test.failure.ignore clean install'
49+
infra.prepareToPublishIncrementals()
50+
junit 'target/surefire-reports/*.xml'
51+
}
3352
}
3453
}
35-
}, failFast: true
54+
parallel branches
55+
}
56+
// Stage part of the library
3657
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"

src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@ public void inheritFrom() throws Exception {
291291
@Test
292292
public void runInPodWithMultipleContainers() throws Exception {
293293
r.assertBuildStatusSuccess(r.waitForCompletion(b));
294-
r.assertLogContains("image: \"jenkins/inbound-agent:", b);
295294
r.assertLogContains("image: \"maven:3.3.9-jdk-8-alpine\"", b);
296295
r.assertLogContains("image: \"golang:1.6.3-alpine\"", b);
297296
r.assertLogContains("My Kubernetes Pipeline", b);

test-in-k8s.sh

100644100755
Lines changed: 9 additions & 13 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,16 @@ 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
17+
# Copy temporary split files
18+
tar cf - "$WORKSPACE_TMP" | kubectl exec -i jenkins -- tar xf -
19+
# Copy plugin files
1720
kubectl exec jenkins -- mkdir /checkout
18-
kubectl cp pom.xml jenkins:/checkout/pom.xml
19-
kubectl cp .mvn jenkins:/checkout/.mvn
20-
kubectl cp src jenkins:/checkout/src
21-
if [ -v TEST ]
22-
then
23-
args="-Dtest=$TEST test"
24-
else
25-
args=verify
26-
fi
21+
tar cf - pom.xml .mvn src | kubectl exec -i jenkins -- tar xf - -C /checkout
2722
kubectl exec jenkins -- \
2823
mvn \
2924
-B \
@@ -34,5 +29,6 @@ kubectl exec jenkins -- \
3429
-DslaveAgentPort=$tcp_port \
3530
-Djenkins.host.address=jenkins.kubernetes-plugin-test.svc.cluster.local \
3631
-Dmaven.test.failure.ignore \
37-
$args
32+
verify \
33+
"$@"
3834
kubectl exec jenkins -- sh -c 'fgrep skipped /checkout/target/surefire-reports/*.xml' || :

0 commit comments

Comments
 (0)