Skip to content

Commit 662d167

Browse files
authored
CLOUD-815 Fix Jenkins pipeline which is being run upon PR (#1375)
1 parent 3e517e4 commit 662d167

File tree

1 file changed

+31
-39
lines changed

1 file changed

+31
-39
lines changed

Jenkinsfile

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
GKERegion="us-central1-a"
1+
region="us-central1-a"
22
testUrlPrefix="https://percona-jenkins-artifactory-public.s3.amazonaws.com/cloud-psmdb-operator"
33
tests=[]
44

55
void 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 """
88
export KUBECONFIG=/tmp/$CLUSTER_NAME-${CLUSTER_SUFFIX}
9-
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
10-
source $HOME/google-cloud-sdk/path.bash.inc
119
ret_num=0
1210
while [ \${ret_num} -lt 15 ]; do
1311
ret_val=0
1412
gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
1513
gcloud config set project $GCP_PROJECT
16-
gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $GKERegion --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $GKERegion --quiet || true
17-
gcloud container clusters create --zone $GKERegion $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.25 --machine-type=n1-standard-4 --preemptible --num-nodes=3 --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 --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX} --cluster-version=1.25 --machine-type=n1-standard-4 --preemptible --num-nodes=3 --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 && \
1816
kubectl create clusterrolebinding cluster-admin-binding --clusterrole cluster-admin --user jenkins@"$GCP_PROJECT".iam.gserviceaccount.com || ret_val=\$?
1917
if [ \${ret_val} -eq 0 ]; then break; fi
2018
ret_num=\$((ret_num + 1))
2119
done
2220
if [ \${ret_num} -eq 15 ]; then
23-
gcloud container clusters list --filter $CLUSTER_NAME-${CLUSTER_SUFFIX} --zone $GKERegion --format='csv[no-heading](name)' | xargs gcloud container clusters delete --zone $GKERegion --quiet || true
21+
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
2422
exit 1
2523
fi
2624
"""
@@ -31,8 +29,6 @@ void shutdownCluster(String CLUSTER_SUFFIX) {
3129
withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) {
3230
sh """
3331
export KUBECONFIG=/tmp/$CLUSTER_NAME-${CLUSTER_SUFFIX}
34-
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
35-
source $HOME/google-cloud-sdk/path.bash.inc
3632
gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
3733
gcloud config set project $GCP_PROJECT
3834
for namespace in \$(kubectl get namespaces --no-headers | awk '{print \$1}' | grep -vE "^kube-|^openshift" | sed '/-operator/ s/^/1-/' | sort | sed 's/^1-//'); do
@@ -44,17 +40,15 @@ void shutdownCluster(String CLUSTER_SUFFIX) {
4440
kubectl delete pods --all -n \$namespace --force --grace-period=0 || true
4541
done
4642
kubectl get svc --all-namespaces || true
47-
gcloud container clusters delete --zone $GKERegion $CLUSTER_NAME-${CLUSTER_SUFFIX}
43+
gcloud container clusters delete --zone $region $CLUSTER_NAME-${CLUSTER_SUFFIX}
4844
"""
4945
}
5046
}
5147

5248
void deleteOldClusters(String FILTER) {
5349
withCredentials([string(credentialsId: 'GCP_PROJECT_ID', variable: 'GCP_PROJECT'), file(credentialsId: 'gcloud-key-file', variable: 'CLIENT_SECRET_FILE')]) {
5450
sh """
55-
if [ -f $HOME/google-cloud-sdk/path.bash.inc ]; then
56-
export USE_GKE_GCLOUD_AUTH_PLUGIN=True
57-
source $HOME/google-cloud-sdk/path.bash.inc
51+
if gcloud --version > /dev/null 2>&1; then
5852
gcloud auth activate-service-account --key-file $CLIENT_SECRET_FILE
5953
gcloud config set project $GCP_PROJECT
6054
for GKE_CLUSTER in \$(gcloud container clusters list --format='csv[no-heading](name)' --filter="$FILTER"); do
@@ -70,7 +64,7 @@ void deleteOldClusters(String FILTER) {
7064
break
7165
fi
7266
done
73-
gcloud container clusters delete --async --zone $GKERegion --quiet \$GKE_CLUSTER || true
67+
gcloud container clusters delete --async --zone $region --quiet \$GKE_CLUSTER || true
7468
done
7569
fi
7670
"""
@@ -208,7 +202,6 @@ void runTest(Integer TEST_ID) {
208202
export DEBUG_TESTS=1
209203
fi
210204
export KUBECONFIG=/tmp/$CLUSTER_NAME-$clusterSuffix
211-
source $HOME/google-cloud-sdk/path.bash.inc
212205
./e2e-tests/$testName/run
213206
"""
214207
}
@@ -278,35 +271,35 @@ pipeline {
278271
}
279272
}
280273
}
281-
sh '''
282-
sudo yum install -y https://repo.percona.com/yum/percona-release-latest.noarch.rpm || true
283-
sudo percona-release enable-only tools
284-
sudo yum install -y | true
274+
sh """
275+
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
276+
kubectl version --client --output=yaml
285277
286-
if [ ! -d $HOME/google-cloud-sdk/bin ]; then
287-
rm -rf $HOME/google-cloud-sdk
288-
curl https://sdk.cloud.google.com | bash
289-
fi
278+
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
290279
291-
source $HOME/google-cloud-sdk/path.bash.inc
292-
gcloud components install alpha
293-
gcloud components install kubectl
280+
sudo sh -c "curl -s -L https://github.com/mikefarah/yq/releases/download/v4.35.1/yq_linux_amd64 > /usr/local/bin/yq"
281+
sudo chmod +x /usr/local/bin/yq
294282
295-
curl -fsSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
296-
curl -s -L https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz \
297-
| sudo tar -C /usr/local/bin --strip-components 1 --wildcards -zxvpf - '*/oc'
283+
sudo sh -c "curl -s -L https://github.com/jqlang/jq/releases/download/jq-1.6/jq-linux64 > /usr/local/bin/jq"
284+
sudo chmod +x /usr/local/bin/jq
298285
299-
curl -s -L https://github.com/mitchellh/golicense/releases/latest/download/golicense_0.2.0_linux_x86_64.tar.gz \
300-
| sudo tar -C /usr/local/bin --wildcards -zxvpf -
286+
sudo tee /etc/yum.repos.d/google-cloud-sdk.repo << EOF
287+
[google-cloud-cli]
288+
name=Google Cloud CLI
289+
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el7-x86_64
290+
enabled=1
291+
gpgcheck=1
292+
repo_gpgcheck=0
293+
gpgkey=https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
294+
EOF
295+
sudo yum install -y google-cloud-cli google-cloud-cli-gke-gcloud-auth-plugin
296+
297+
curl -sL https://github.com/mitchellh/golicense/releases/latest/download/golicense_0.2.0_linux_x86_64.tar.gz | sudo tar -C /usr/local/bin -xzf - golicense
298+
"""
301299

302-
sudo sh -c "curl -s -L https://github.com/mikefarah/yq/releases/download/v4.34.1/yq_linux_amd64 > /usr/local/bin/yq"
303-
sudo chmod +x /usr/local/bin/yq
304-
sudo sh -c "curl -s -L https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 > /usr/local/bin/jq"
305-
sudo chmod +x /usr/local/bin/jq
306-
'''
307300
withCredentials([file(credentialsId: 'cloud-secret-file', variable: 'CLOUD_SECRET_FILE')]) {
308301
sh '''
309-
cp $CLOUD_SECRET_FILE ./e2e-tests/conf/cloud-secret.yml
302+
cp $CLOUD_SECRET_FILE e2e-tests/conf/cloud-secret.yml
310303
'''
311304
}
312305
deleteOldClusters("jen-psmdb-$CHANGE_ID")
@@ -498,9 +491,8 @@ pipeline {
498491
}
499492
deleteOldClusters("$CLUSTER_NAME")
500493
sh """
501-
sudo docker system prune -fa
502-
sudo rm -rf ./*
503-
sudo rm -rf $HOME/google-cloud-sdk
494+
sudo docker system prune --volumes -af
495+
sudo rm -rf *
504496
"""
505497
deleteDir()
506498
}

0 commit comments

Comments
 (0)