-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: check if gcloud is authenticated otherwise fail (15s) #222
base: master
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍
|
/improve |
/improve |
/improve |
/improve |
/improve |
PR Code Suggestions ✨Latest suggestions up to ceccb12
Previous suggestionsSuggestions up to commit 6a9cd99
Suggestions up to commit b310198
Suggestions up to commit aaddcba
Suggestions up to commit d873af3
|
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | ||
|
||
# if service account is empty, wait for it to be set. | ||
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | ||
MAX_ATTEMPTS=3 | ||
i=0 | ||
while [ $i -lt $MAX_ATTEMPTS ]; do | ||
echo "Waiting for gcloud to authenticate..." | ||
sleep 5s | ||
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | ||
if [ -n "${GCP_SERVICE_ACCOUNT}" ]; then | ||
break | ||
fi | ||
i=$((i+1)) | ||
done | ||
fi | ||
|
||
# if still empty, fail. | ||
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | ||
echo "Failed to authenticate with gcloud after multiple attempts." | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | |
# if service account is empty, wait for it to be set. | |
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | |
MAX_ATTEMPTS=3 | |
i=0 | |
while [ $i -lt $MAX_ATTEMPTS ]; do | |
echo "Waiting for gcloud to authenticate..." | |
sleep 5s | |
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | |
if [ -n "${GCP_SERVICE_ACCOUNT}" ]; then | |
break | |
fi | |
i=$((i+1)) | |
done | |
fi | |
# if still empty, fail. | |
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | |
echo "Failed to authenticate with gcloud after multiple attempts." | |
exit 1 | |
fi | |
if [ "${DISABLE_GCP_SERVICE_ACCOUNT_CHECK:-0}" != "1" ]; then | |
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | |
# if service account is empty, wait for it to be set. | |
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | |
MAX_ATTEMPTS=3 | |
i=0 | |
while [ $i -lt $MAX_ATTEMPTS ]; do | |
echo "Waiting for gcloud to authenticate..." | |
sleep 5s | |
GCP_SERVICE_ACCOUNT=$(gcloud auth list --filter=status:ACTIVE --format="value(account)") | |
if [ -n "${GCP_SERVICE_ACCOUNT}" ]; then | |
break | |
fi | |
i=$((i+1)) | |
done | |
fi | |
# if still empty, fail. | |
if [ -z "${GCP_SERVICE_ACCOUNT}" ]; then | |
echo "Failed to authenticate with gcloud after multiple attempts." | |
exit 1 | |
fi | |
fi |
I would prefer to have a method to skip this check. What do you think?
PR Type
Enhancement
Description
Changes walkthrough 📝
.gitlab-ci-template.yml
Improve gcloud authentication resilience
templates/.gitlab-ci-template.yml