1- region= " us-central1-a"
2- testUrlPrefix= " https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator"
3- tests= []
1+ region = ' us-central1-a'
2+ testUrlPrefix = ' https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator'
3+ tests = []
44
55void createCluster (String CLUSTER_SUFFIX ) {
66 withCredentials([string(credentialsId : ' GCP_PROJECT_ID' , variable : ' GCP_PROJECT' ), file(credentialsId : ' gcloud-key-file' , variable : ' CLIENT_SECRET_FILE' )]) {
77 sh """
8- NODES_NUM=3
9- export KUBECONFIG=/tmp/$CLUSTER_NAME -${ CLUSTER_SUFFIX}
8+ export KUBECONFIG=/tmp/${ CLUSTER_NAME} -${ CLUSTER_SUFFIX}
9+ gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
10+ gcloud config set project $GCP_PROJECT
1011 ret_num=0
1112 while [ \$ {ret_num} -lt 15 ]; do
1213 ret_val=0
13- gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
14- gcloud config set project $GCP_PROJECT
15- gcloud container clusters list --filter $CLUSTER_NAME -${ CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true
16- gcloud container clusters create --zone $region $CLUSTER_NAME -${ CLUSTER_SUFFIX} --cluster-version=1.31 --machine-type=n1-standard-4 --preemptible --disk-size 30 --num-nodes=\$ NODES_NUM --network=jenkins-vpc --subnetwork=jenkins-${ CLUSTER_SUFFIX} --no-enable-autoupgrade --cluster-ipv4-cidr=/21 --labels delete-cluster-after-hours=6 --enable-ip-alias --workload-pool=cloud-dev-112233.svc.id.goog && \
14+ gcloud container clusters list --filter ${ CLUSTER_NAME} -${ CLUSTER_SUFFIX} --zone ${ region} --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone ${ region} --quiet || true
15+ gcloud container clusters create ${ CLUSTER_NAME} -${ CLUSTER_SUFFIX} \
16+ --preemptible \
17+ --zone=${ region} \
18+ --machine-type='n1-standard-4' \
19+ --cluster-version='1.31' \
20+ --num-nodes=3 \
21+ --labels='delete-cluster-after-hours=6' \
22+ --disk-size=30 \
23+ --network=jenkins-vpc \
24+ --subnetwork=jenkins-${ CLUSTER_SUFFIX} \
25+ --cluster-ipv4-cidr=/21 \
26+ --enable-ip-alias \
27+ --no-enable-autoupgrade \
28+ --monitoring=NONE \
29+ --logging=NONE \
30+ --no-enable-managed-prometheus \
31+ --workload-pool=cloud-dev-112233.svc.id.goog \
32+ --quiet && \
1733 kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user jenkins@"$GCP_PROJECT ".iam.gserviceaccount.com || ret_val=\$ ?
1834 if [ \$ {ret_val} -eq 0 ]; then break; fi
1935 ret_num=\$ ((ret_num + 1))
2036 done
2137 if [ \$ {ret_num} -eq 15 ]; then
22- gcloud container clusters list --filter $CLUSTER_NAME -${ CLUSTER_SUFFIX} --zone $region --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $region --quiet || true
38+ gcloud container clusters list --filter ${ CLUSTER_NAME} -${ CLUSTER_SUFFIX} --zone ${ region} --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone ${ region} --quiet || true
2339 exit 1
2440 fi
2541 """
@@ -29,7 +45,7 @@ void createCluster(String CLUSTER_SUFFIX) {
2945void shutdownCluster (String CLUSTER_SUFFIX ) {
3046 withCredentials([string(credentialsId : ' GCP_PROJECT_ID' , variable : ' GCP_PROJECT' ), file(credentialsId : ' gcloud-key-file' , variable : ' CLIENT_SECRET_FILE' )]) {
3147 sh """
32- export KUBECONFIG=/tmp/$CLUSTER_NAME -${ CLUSTER_SUFFIX}
48+ export KUBECONFIG=/tmp/${ CLUSTER_NAME} -${ CLUSTER_SUFFIX}
3349 gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
3450 gcloud config set project $GCP_PROJECT
3551 for namespace in \$ (kubectl get namespaces --no-headers | awk '{print \$ 1}' | grep -vE "^kube-|^openshift" | sed '/-operator/ s/^/1-/' | sort | sed 's/^1-//'); do
@@ -41,7 +57,7 @@ void shutdownCluster(String CLUSTER_SUFFIX) {
4157 kubectl delete pods --all -n \$ namespace --force --grace-period=0 || true
4258 done
4359 kubectl get svc --all-namespaces || true
44- gcloud container clusters delete --zone $region $ CLUSTER_NAME -${ CLUSTER_SUFFIX}
60+ gcloud container clusters delete --zone ${ region} ${ CLUSTER_NAME} -${ CLUSTER_SUFFIX}
4561 """
4662 }
4763}
@@ -65,7 +81,7 @@ void deleteOldClusters(String FILTER) {
6581 break
6682 fi
6783 done
68- gcloud container clusters delete --async --zone $region --quiet \$ GKE_CLUSTER || true
84+ gcloud container clusters delete --async --zone ${ region} --quiet \$ GKE_CLUSTER || true
6985 done
7086 fi
7187 """
@@ -132,9 +148,9 @@ void markPassedTests() {
132148
133149void printKubernetesStatus (String LOCATION , String CLUSTER_SUFFIX ) {
134150 sh """
135- export KUBECONFIG=/tmp/$CLUSTER_NAME - $ CLUSTER_SUFFIX
151+ export KUBECONFIG=/tmp/${ CLUSTER_NAME} - ${ CLUSTER_SUFFIX}
136152 echo "========== KUBERNETES STATUS $LOCATION TEST =========="
137- gcloud container clusters list|grep -E "NAME|$CLUSTER_NAME - $ CLUSTER_SUFFIX "
153+ gcloud container clusters list|grep -E "NAME|${ CLUSTER_NAME} - ${ CLUSTER_SUFFIX} "
138154 echo
139155 kubectl get nodes
140156 echo
@@ -149,26 +165,51 @@ void printKubernetesStatus(String LOCATION, String CLUSTER_SUFFIX) {
149165 """
150166}
151167
152- TestsReport = ' | Test name | Status |\r\n | ------------- | ------------- |'
168+ String formatTime (def time ) {
169+ if (! time || time == " N/A" ) return " N/A"
170+
171+ try {
172+ def totalSeconds = time as Double
173+ def hours = (totalSeconds / 3600 ) as Integer
174+ def minutes = ((totalSeconds % 3600 ) / 60 ) as Integer
175+ def seconds = (totalSeconds % 60 ) as Integer
176+
177+ return String . format(" %02d:%02d:%02d" , hours, minutes, seconds)
178+
179+ } catch (Exception e) {
180+ println (" Error converting time: ${ e.message} " )
181+ return time. toString()
182+ }
183+ }
184+
185+ TestsReport = ' | Test Name | Result | Time |\r\n | ----------- | -------- | ------ |'
153186TestsReportXML = ' <testsuite name=\\ "PSMDB\\ ">\n '
154187
155188void makeReport () {
156- def wholeTestAmount= tests. size()
189+ def wholeTestAmount = tests. size()
157190 def startedTestAmount = 0
191+ def totalTestTime = 0
158192
159193 for (int i= 0 ; i< tests. size(); i++ ) {
160194 def testName = tests[i][" name" ]
161195 def testResult = tests[i][" result" ]
162196 def testTime = tests[i][" time" ]
163197 def testUrl = " ${ testUrlPrefix} /${ env.GIT_BRANCH} /${ env.GIT_SHORT_COMMIT} /${ testName} .log"
164198
199+ if (testTime instanceof Number ) {
200+ totalTestTime + = testTime
201+ }
202+
165203 if (tests[i][" result" ] != " skipped" ) {
166204 startedTestAmount++
167205 }
168- TestsReport = TestsReport + " \r\n | " + testName + " | [" + testResult + " ](" + testUrl + " ) |"
206+ TestsReport = TestsReport + " \r\n | " + testName + " | [" + testResult + " ](" + testUrl + " ) | " + formatTime(testTime) + " |"
169207 TestsReportXML = TestsReportXML + ' <testcase name=\\ "' + testName + ' \\ " time=\\ "' + testTime + ' \\ "><' + testResult + ' /></testcase>\n '
170208 }
171- TestsReport = TestsReport + " \r\n | We run $startedTestAmount out of $wholeTestAmount |"
209+ TestsReport = TestsReport + " \r\n\r\n | Summary | Value |\r\n | ------- | ----- |"
210+ TestsReport = TestsReport + " \r\n | Tests Run | $startedTestAmount /$wholeTestAmount |"
211+ TestsReport = TestsReport + " \r\n | Job Duration | " + formatTime(currentBuild. duration / 1000 ) + " |"
212+ TestsReport = TestsReport + " \r\n | Total Test Time | " + formatTime(totalTestTime) + " |"
172213 TestsReportXML = TestsReportXML + ' </testsuite>\n '
173214
174215 sh """
@@ -204,7 +245,7 @@ void runTest(Integer TEST_ID) {
204245 waitUntil {
205246 def timeStart = new Date (). getTime()
206247 try {
207- echo " The $testName test was started on cluster $CLUSTER_NAME - $ clusterSuffix !"
248+ echo " The $testName test was started on cluster ${ CLUSTER_NAME} - ${ clusterSuffix} !"
208249 tests[TEST_ID ][" result" ] = " failure"
209250
210251 timeout(time : 90 , unit : ' MINUTES' ) {
@@ -214,7 +255,7 @@ void runTest(Integer TEST_ID) {
214255 else
215256 export DEBUG_TESTS=1
216257 fi
217- export KUBECONFIG=/tmp/$CLUSTER_NAME - $ clusterSuffix
258+ export KUBECONFIG=/tmp/${ CLUSTER_NAME} - ${ clusterSuffix}
218259 time ./e2e-tests/$testName /run
219260 """
220261 }
@@ -244,10 +285,10 @@ void runTest(Integer TEST_ID) {
244285
245286void prepareNode () {
246287 sh """
247- sudo curl -s -L -o /usr/local/bin/kubectl https://dl.k8s.io/release/\$ (curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
288+ sudo curl -sLo /usr/local/bin/kubectl https://dl.k8s.io/release/\$ (curl -Ls https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl && sudo chmod +x /usr/local/bin/kubectl
248289 kubectl version --client --output=yaml
249290
250- curl -fsSL https://get.helm.sh/helm-v3.12 .3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
291+ curl -fsSL https://get.helm.sh/helm-v3.18 .3-linux-amd64.tar.gz | sudo tar -C /usr/local/bin --strip-components 1 -xzf - linux-amd64/helm
251292
252293 sudo curl -fsSL https://github.com/mikefarah/yq/releases/download/v4.44.1/yq_linux_amd64 -o /usr/local/bin/yq && sudo chmod +x /usr/local/bin/yq
253294 sudo curl -fsSL https://github.com/jqlang/jq/releases/download/jq-1.7.1/jq-linux64 -o /usr/local/bin/jq && sudo chmod +x /usr/local/bin/jq
@@ -499,7 +540,7 @@ pipeline {
499540 }
500541 }
501542 options {
502- timeout(time : 3 , unit : ' HOURS' )
543+ timeout(time : 4 , unit : ' HOURS' )
503544 }
504545 parallel {
505546 stage(' cluster1' ) {
0 commit comments