Commit d81ce8b2 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'qa-112-prefer-env-credentials-for-gcloud' into 'master'

Auto DevOps QA: Prefer gcloud credentials from env

See merge request gitlab-org/gitlab-ce!20338
parents 391710f2 2a8d0b59
......@@ -62,6 +62,10 @@ module QA
def gcloud_zone
ENV.fetch('GCLOUD_ZONE')
end
def has_gcloud_credentials?
%w[GCLOUD_ACCOUNT_KEY GCLOUD_ACCOUNT_EMAIL].none? { |var| ENV[var].to_s.empty? }
end
end
end
end
......@@ -50,11 +50,15 @@ module QA
end
def login_if_not_already_logged_in
account = `gcloud auth list --filter=status:ACTIVE --format="value(account)"`
if account.empty?
if Runtime::Env.has_gcloud_credentials?
attempt_login_with_env_vars
else
puts "gcloud account found. Using: #{account} for creating K8s cluster."
account = `gcloud auth list --filter=status:ACTIVE --format="value(account)"`
if account.empty?
raise "Failed to login to gcloud. No credentials provided in environment and no credentials found locally."
else
puts "gcloud account found. Using: #{account} for creating K8s cluster."
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment