blob: 42961ff2a2b2fff77aaa9859cdc675e6ea8e8b77 [file] [log] [blame]
Hung-Wei Chiud27e33b2020-09-03 12:05:41 -07001pipeline {
2 agent {
3 docker {
4 image 'ubuntu:18.04'
5 args '-u root:sudo'
6 }
7 }
8 environment {
9 KUBECONFIG = credentials("${params.k8s_config}")
10 }
11 stages {
12 stage('Install tools') {
13 steps {
14 sh '''
15 set -x
16 apt-get update -y
17 apt-get install -y curl wget jq git
18
19 # Install kubectl
20 curl -LO "https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl"
21 chmod +x ./kubectl
22 mv ./kubectl /usr/local/bin/kubectl
23
24 # Test Kubectl & Rancher
25 kubectl get nodes
26 '''
27 }
28 }
29 stage('Parallel Stage') {
30 parallel {
31 stage('onos') {
32 steps {
33 sh(script: "date -u")
34 build(job: "${params.job_name}-onos")
35 }
36 }
37 stage('stratum') {
38 steps {
39 sh(script: "date -u")
40 build(job: "${params.job_name}-stratum")
41 }
42 }
43 stage('telegraf') {
44 steps {
45 sh(script: "date -u")
46 build(job: "${params.job_name}-telegraf")
47 }
48 }
49 }
50 }
51 stage('E2E Testing') {
52 options {
53 timeout(time: 120, unit: "SECONDS")
54 }
55 steps {
56 sh """
57 echo ${params.target_server}
58 timestamp=\$(date +%s)
59 if [ ! -z "${params.target_server}" ]; then
60 kubectl delete --wait=true ds -l test=e2e || true
61cat <<EOF > test.yaml
62apiVersion: apps/v1
63kind: DaemonSet
64metadata:
65 name: ping-test-\${timestamp}
66 labels:
67 test: e2e-\${timestamp}
68spec:
69 selector:
70 matchLabels:
71 test: e2e-\${timestamp}
72 template:
73 metadata:
74 labels:
75 test: e2e-\${timestamp}
76 spec:
77 hostNetwork: true
78 terminationGracePeriodSeconds: 5
79 initContainers:
80 - name: ping-test
81 image: alpine:3.12.0
82 command: ["sh", "-c", "until ping ${params.target_server} -c1 -W 4; do echo 'ping retry'; sleep 3; done;"]
83 containers:
84 - name: ping-test-wait
85 image: alpine:3.12.0
86 command: ["sh", "-c", "sleep 100000"]
87 restartPolicy: Always
88EOF
89 kubectl apply -f test.yaml
90 number=\$(kubectl get --no-headers ds -ltest=e2e-\${timestamp} -o custom-columns=':.status.desiredNumberScheduled')
91 echo "\${number}"
92 until [ \${number} -eq \$(kubectl get pods -l test=e2e-\${timestamp} --no-headers -o custom-columns=':.status.phase' | grep Running | wc -l) ]; do echo 'wait ping completed'; sleep 5; done;
93 fi
94 """
95 }
96 }
97 }
98 post {
99 always {
100 sh """
101 if [ ! -z "${params.target_server}" ]; then
102 kubectl delete -f test.yaml
103 fi
104 """
105 cleanWs()
106 }
107 }
108}