@@ -23,6 +23,41 @@ steps:
2323 cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
2424 waitFor : ["-"]
2525
26+ - name : " gcr.io/google.com/cloudsdktool/cloud-sdk"
27+ id : " cleanup-old-keys"
28+ entrypoint : " bash"
29+ args :
30+ - " -c"
31+ - |
32+ #!/bin/bash
33+ set -e
34+
35+ echo "Fetching OS Login SSH keys..."
36+ echo "Removing all keys."
37+ echo "---------------------------------------------------------------------"
38+
39+ FINGERPRINTS_TO_DELETE=$$(gcloud compute os-login ssh-keys list \
40+ --format="value(fingerprint)")
41+
42+ echo "Keys to delete: $$FINGERPRINTS_TO_DELETE"
43+
44+ if [ -z "$$FINGERPRINTS_TO_DELETE" ]; then
45+ echo "No keys found to delete. Nothing to do."
46+ exit 0
47+ fi
48+
49+ while IFS= read -r FINGERPRINT; do
50+ if [ -n "$$FINGERPRINT" ]; then
51+ echo "Deleting key with fingerprint: $$FINGERPRINT"
52+ gcloud compute os-login ssh-keys remove \
53+ --key="$$FINGERPRINT" \
54+ --quiet || true
55+ fi
56+ done <<< "$$FINGERPRINTS_TO_DELETE"
57+
58+ echo "---------------------------------------------------------------------"
59+ echo "Cleanup complete."
60+
2661 # Step 1 Create a GCE VM to run the tests.
2762 # The VM is created in the same zone as the buckets to test rapid storage features.
2863 # It's given the 'cloud-platform' scope to allow it to access GCS and other services.
@@ -63,12 +98,12 @@ steps:
6398 sleep 15
6499 done
65100 # copy the script to the VM
66- gcloud compute scp cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
101+ gcloud compute scp packages/google-cloud-storage/ cloudbuild/run_zonal_tests.sh ${_VM_NAME}:~ --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine
67102
68103 # Execute the script on the VM via SSH.
69104 # Capture the exit code to ensure cleanup happens before the build fails.
70105 set +e
71- gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n {_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash run_zonal_tests.sh"
106+ gcloud compute ssh ${_VM_NAME} --zone=${_ZONE} --internal-ip --ssh-key-file=/workspace/.ssh/google_compute_engine --command="ulimit -n $ {_ULIMIT}; COMMIT_SHA=${COMMIT_SHA} _ZONAL_BUCKET=${_ZONAL_BUCKET} CROSS_REGION_BUCKET=${_CROSS_REGION_BUCKET} _PR_NUMBER=${_PR_NUMBER} bash run_zonal_tests.sh"
72107 EXIT_CODE=$?
73108 set -e
74109
@@ -80,6 +115,7 @@ steps:
80115 waitFor :
81116 - " create-vm"
82117 - " generate-ssh-key"
118+ - " cleanup-old-keys"
83119
84120 - name : " gcr.io/google.com/cloudsdktool/cloud-sdk"
85121 id : " cleanup-ssh-key"
0 commit comments