Module: Gitlab::QA::Runtime::Env

Extended by:
Env
Included in:
Env
Defined in:
lib/gitlab/qa/runtime/env.rb

Constant Summary collapse

ENV_VARIABLES =

Variables that are used in tests and are passed through to the docker container that executes the tests. These variables should be listed in /docs/what_tests_can_be_run.md#supported-gitlab-environment-variables unless they’re defined elsewhere (e.g.: docs.gitlab.com/ee/ci/variables/predefined_variables.html)

{
  'QA_IMAGE' => :qa_image,
  'QA_REMOTE_GRID' => :remote_grid,
  'QA_REMOTE_GRID_USERNAME' => :remote_grid_username,
  'QA_REMOTE_GRID_ACCESS_KEY' => :remote_grid_access_key,
  'QA_REMOTE_GRID_PROTOCOL' => :remote_grid_protocol,
  'QA_BROWSER' => :browser,
  'GITLAB_API_BASE' => :api_base,
  'GITLAB_ADMIN_USERNAME' => :admin_username,
  'GITLAB_ADMIN_PASSWORD' => :admin_password,
  'GITLAB_USERNAME' => :user_username,
  'GITLAB_PASSWORD' => :user_password,
  'GITLAB_LDAP_USERNAME' => :ldap_username,
  'GITLAB_LDAP_PASSWORD' => :ldap_password,
  'GITLAB_FORKER_USERNAME' => :forker_username,
  'GITLAB_FORKER_PASSWORD' => :forker_password,
  'GITLAB_USER_TYPE' => :user_type,
  'GITLAB_SANDBOX_NAME' => :gitlab_sandbox_name,
  'GITLAB_QA_ACCESS_TOKEN' => :qa_access_token,
  'GITLAB_QA_ADMIN_ACCESS_TOKEN' => :qa_admin_access_token,
  'GITHUB_ACCESS_TOKEN' => :github_access_token,
  'GITLAB_URL' => :gitlab_url,
  'SIMPLE_SAML_HOSTNAME' => :simple_saml_hostname,
  'SIMPLE_SAML_FINGERPRINT' => :simple_saml_fingerprint,
  'ACCEPT_INSECURE_CERTS' => :accept_insecure_certs,
  'EE_LICENSE' => :ee_license,
  'GCLOUD_ACCOUNT_EMAIL' => :gcloud_account_email,
  'GCLOUD_ACCOUNT_KEY' => :gcloud_account_key,
  'CLOUDSDK_CORE_PROJECT' => :cloudsdk_core_project,
  'GCLOUD_REGION' => :gcloud_region,
  'SIGNUP_DISABLED' => :signup_disabled,
  'QA_ADDITIONAL_REPOSITORY_STORAGE' => :qa_additional_repository_storage,
  'QA_PRAEFECT_REPOSITORY_STORAGE' => :qa_praefect_repository_storage,
  'QA_GITALY_NON_CLUSTER_STORAGE' => :qa_gitaly_non_cluster_storage,
  'QA_COOKIES' => :qa_cookie,
  'QA_DEBUG' => :qa_debug,
  'QA_DEFAULT_BRANCH' => :qa_default_branch,
  'QA_LOG_PATH' => :qa_log_path,
  'QA_CAN_TEST_ADMIN_FEATURES' => :qa_can_test_admin_features,
  'QA_CAN_TEST_GIT_PROTOCOL_V2' => :qa_can_test_git_protocol_v2,
  'QA_CAN_TEST_PRAEFECT' => :qa_can_test_praefect,
  'QA_DISABLE_RSPEC_RETRY' => :qa_disable_rspec_retry,
  'QA_SIMULATE_SLOW_CONNECTION' => :qa_simulate_slow_connection,
  'QA_SLOW_CONNECTION_LATENCY_MS' => :qa_slow_connection_latency_ms,
  'QA_SLOW_CONNECTION_THROUGHPUT_KBPS' => :qa_slow_connection_throughput_kbps,
  'GITLAB_QA_USERNAME_1' => :gitlab_qa_username_1,
  'GITLAB_QA_PASSWORD_1' => :gitlab_qa_password_1,
  'GITLAB_QA_USERNAME_2' => :gitlab_qa_username_2,
  'GITLAB_QA_PASSWORD_2' => :gitlab_qa_password_2,
  'GITHUB_USERNAME' => :github_username,
  'GITHUB_PASSWORD' => :github_password,
  'KNAPSACK_GENERATE_REPORT' => :knapsack_generate_report,
  'KNAPSACK_REPORT_PATH' => :knapsack_report_path,
  'KNAPSACK_TEST_FILE_PATTERN' => :knapsack_test_file_pattern,
  'KNAPSACK_TEST_DIR' => :knapsack_test_dir,
  'CI' => :ci,
  'CI_JOB_NAME' => :ci_job_name,
  'CI_JOB_URL' => :ci_job_url,
  'CI_RUNNER_ID' => :ci_runner_id,
  'CI_SERVER_HOST' => :ci_server_host,
  'CI_SERVER_PERSONAL_ACCESS_TOKEN' => :ci_server_personal_access_token,
  'CI_NODE_INDEX' => :ci_node_index,
  'CI_NODE_TOTAL' => :ci_node_total,
  'CI_PROJECT_NAME' => :ci_project_name,
  'GITLAB_CI' => :gitlab_ci,
  'QA_SKIP_PULL' => :qa_skip_pull,
  'ELASTIC_URL' => :elastic_url,
  'GITLAB_QA_LOOP_RUNNER_MINUTES' => :gitlab_qa_loop_runner_minutes,
  'MAILHOG_HOSTNAME' => :mailhog_hostname,
  'SLACK_QA_CHANNEL' => :slack_qa_channel,
  'CI_SLACK_WEBHOOK_URL' => :ci_slack_webhook_url,
  'SLACK_ICON_EMOJI' => :slack_icon_emoji,
  'GITLAB_QA_FORMLESS_LOGIN_TOKEN' => :gitlab_qa_formless_login_token,
  'GEO_MAX_FILE_REPLICATION_TIME' => :geo_max_file_replication_time,
  'GEO_MAX_DB_REPLICATION_TIME' => :geo_max_db_replication_time,
  'JIRA_HOSTNAME' => :jira_hostname,
  'JIRA_ADMIN_USERNAME' => :jira_admin_username,
  'JIRA_ADMIN_PASSWORD' => :jira_admin_password,
  'CACHE_NAMESPACE_NAME' => :cache_namespace_name,
  'DEPLOY_VERSION' => :deploy_version,
  'GITLAB_QA_USER_AGENT' => :gitlab_qa_user_agent,
  'GEO_FAILOVER' => :geo_failover,
  'GITLAB_INITIAL_ROOT_PASSWORD' => :initial_root_password
}.freeze

Instance Method Summary collapse

Instance Method Details

#ci_api_v4_urlObject



136
137
138
# File 'lib/gitlab/qa/runtime/env.rb', line 136

def ci_api_v4_url
  ENV['CI_API_V4_URL']
end

#ci_commit_ref_nameObject



164
165
166
# File 'lib/gitlab/qa/runtime/env.rb', line 164

def ci_commit_ref_name
  ENV['CI_COMMIT_REF_NAME']
end

#ci_job_nameObject



140
141
142
# File 'lib/gitlab/qa/runtime/env.rb', line 140

def ci_job_name
  ENV['CI_JOB_NAME']
end

#ci_job_tokenObject



144
145
146
# File 'lib/gitlab/qa/runtime/env.rb', line 144

def ci_job_token
  ENV['CI_JOB_TOKEN']
end

#ci_pipeline_idObject



156
157
158
# File 'lib/gitlab/qa/runtime/env.rb', line 156

def ci_pipeline_id
  ENV['CI_PIPELINE_ID']
end

#ci_pipeline_sourceObject



148
149
150
# File 'lib/gitlab/qa/runtime/env.rb', line 148

def ci_pipeline_source
  ENV['CI_PIPELINE_SOURCE']
end

#ci_pipeline_urlObject



152
153
154
# File 'lib/gitlab/qa/runtime/env.rb', line 152

def ci_pipeline_url
  ENV['CI_PIPELINE_URL']
end

#ci_project_idObject



160
161
162
# File 'lib/gitlab/qa/runtime/env.rb', line 160

def ci_project_id
  ENV['CI_PROJECT_ID']
end

#default_branchObject



108
109
110
# File 'lib/gitlab/qa/runtime/env.rb', line 108

def default_branch
  ENV['QA_DEFAULT_BRANCH'] || 'master'
end

#deploy_environmentObject



204
205
206
# File 'lib/gitlab/qa/runtime/env.rb', line 204

def deploy_environment
  ENV['DEPLOY_ENVIRONMENT'] || pipeline_from_project_name
end

#dev_access_token_variableObject



184
185
186
# File 'lib/gitlab/qa/runtime/env.rb', line 184

def dev_access_token_variable
  env_value_if_defined('GITLAB_QA_DEV_ACCESS_TOKEN')
end

#elastic_versionObject



212
213
214
# File 'lib/gitlab/qa/runtime/env.rb', line 212

def elastic_version
  ENV['ELASTIC_VERSION'] || '6.4.2'.freeze
end

#geo_failover?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'lib/gitlab/qa/runtime/env.rb', line 294

def geo_failover?
  enabled?(ENV['GEO_FAILOVER'], default: false)
end

#gitlab_api_baseObject



124
125
126
# File 'lib/gitlab/qa/runtime/env.rb', line 124

def gitlab_api_base
  ENV['GITLAB_API_BASE'] || 'https://gitlab.com/api/v4'
end

#gitlab_availability_timeoutObject



112
113
114
# File 'lib/gitlab/qa/runtime/env.rb', line 112

def gitlab_availability_timeout
  ENV.fetch('GITLAB_QA_AVAILABILITY_TIMEOUT', 360).to_i
end

#gitlab_bot_multi_project_pipeline_polling_tokenObject



128
129
130
# File 'lib/gitlab/qa/runtime/env.rb', line 128

def gitlab_bot_multi_project_pipeline_polling_token
  ENV['GITLAB_BOT_MULTI_PROJECT_PIPELINE_POLLING_TOKEN']
end

#gitlab_ci_api_tokenObject



132
133
134
# File 'lib/gitlab/qa/runtime/env.rb', line 132

def gitlab_ci_api_token
  ENV['GITLAB_CI_API_TOKEN']
end

#gitlab_dev_usernameObject



120
121
122
# File 'lib/gitlab/qa/runtime/env.rb', line 120

def gitlab_dev_username
  ENV['GITLAB_DEV_USERNAME'] || 'gitlab-qa-bot'
end

#gitlab_usernameObject



116
117
118
# File 'lib/gitlab/qa/runtime/env.rb', line 116

def gitlab_username
  ENV['GITLAB_USERNAME'] || 'gitlab-qa'
end

#host_artifacts_dirObject



208
209
210
# File 'lib/gitlab/qa/runtime/env.rb', line 208

def host_artifacts_dir
  @host_artifacts_dir ||= File.join(ENV['QA_ARTIFACTS_DIR'] || '/tmp/gitlab-qa', Runtime::Env.run_id)
end

#initial_root_passwordObject



192
193
194
# File 'lib/gitlab/qa/runtime/env.rb', line 192

def initial_root_password
  ENV['GITLAB_INITIAL_ROOT_PASSWORD'] || '5iveL!fe'
end

#override_default_password!Object



283
284
285
286
287
288
# File 'lib/gitlab/qa/runtime/env.rb', line 283

def override_default_password!
  require_initial_password!

  ENV['GITLAB_PASSWORD'] = initial_root_password
  ENV['GITLAB_ADMIN_PASSWORD'] = initial_root_password
end

#pipeline_from_project_nameObject



168
169
170
171
172
173
174
175
176
177
178
# File 'lib/gitlab/qa/runtime/env.rb', line 168

def pipeline_from_project_name
  if ci_project_name.to_s.start_with?('gitlab-qa')
    if ENV['TOP_UPSTREAM_SOURCE_JOB'].to_s.start_with?('https://ops.gitlab.net')
      'staging-orchestrated'
    else
      QA::Runtime::Env.default_branch
    end
  else
    ci_project_name
  end
end

#qa_container_registry_access_tokenObject



196
197
198
# File 'lib/gitlab/qa/runtime/env.rb', line 196

def qa_container_registry_access_token
  ENV['GITLAB_QA_CONTAINER_REGISTRY_ACCESS_TOKEN']
end

#qa_dev_access_tokenObject



188
189
190
# File 'lib/gitlab/qa/runtime/env.rb', line 188

def qa_dev_access_token
  ENV['GITLAB_QA_DEV_ACCESS_TOKEN']
end

#qa_issue_urlObject



200
201
202
# File 'lib/gitlab/qa/runtime/env.rb', line 200

def qa_issue_url
  ENV['GITLAB_QA_ISSUE_URL']
end

#require_ci_slack_webhook_url!Object

Raises:

  • (ArgumentError)


259
260
261
262
263
# File 'lib/gitlab/qa/runtime/env.rb', line 259

def require_ci_slack_webhook_url!
  return unless ENV['CI_SLACK_WEBHOOK_URL'].to_s.strip.empty?

  raise ArgumentError, "Please provide CI_SLACK_WEBHOOK_URL"
end

#require_initial_password!Object

Raises:

  • (ArgumentError)


271
272
273
274
275
# File 'lib/gitlab/qa/runtime/env.rb', line 271

def require_initial_password!
  return unless ENV['GITLAB_INITIAL_ROOT_PASSWORD'].to_s.strip.empty?

  raise ArgumentError, "Environment variable GITLAB_INITIAL_ROOT_PASSWORD must be provided to set an initial root password."
end

#require_kubernetes_environment!Object



265
266
267
268
269
# File 'lib/gitlab/qa/runtime/env.rb', line 265

def require_kubernetes_environment!
  %w[GCLOUD_ACCOUNT_EMAIL GCLOUD_ACCOUNT_KEY CLOUDSDK_CORE_PROJECT].each do |env_key|
    raise ArgumentError, "Environment variable #{env_key} must be set to run kubernetes specs" unless ENV.key?(env_key)
  end
end

#require_license!Object

Raises:

  • (ArgumentError)


229
230
231
232
233
# File 'lib/gitlab/qa/runtime/env.rb', line 229

def require_license!
  return if ENV.include?('EE_LICENSE')

  raise ArgumentError, 'GitLab License is not available. Please load a license into EE_LICENSE env variable.'
end

#require_no_license!Object

Raises:

  • (ArgumentError)


235
236
237
238
239
# File 'lib/gitlab/qa/runtime/env.rb', line 235

def require_no_license!
  return unless ENV.include?('EE_LICENSE')

  raise ArgumentError, "Unexpected EE_LICENSE provided. Please unset it to continue."
end

#require_qa_access_token!Object

Raises:

  • (ArgumentError)


241
242
243
244
245
# File 'lib/gitlab/qa/runtime/env.rb', line 241

def require_qa_access_token!
  return unless ENV['GITLAB_QA_ACCESS_TOKEN'].to_s.strip.empty?

  raise ArgumentError, "Please provide GITLAB_QA_ACCESS_TOKEN"
end

#require_qa_dev_access_token!Object

Raises:

  • (ArgumentError)


247
248
249
250
251
# File 'lib/gitlab/qa/runtime/env.rb', line 247

def require_qa_dev_access_token!
  return unless ENV['GITLAB_QA_DEV_ACCESS_TOKEN'].to_s.strip.empty?

  raise ArgumentError, "Please provide GITLAB_QA_DEV_ACCESS_TOKEN"
end

#require_slack_qa_channel!Object

Raises:

  • (ArgumentError)


253
254
255
256
257
# File 'lib/gitlab/qa/runtime/env.rb', line 253

def require_slack_qa_channel!
  return unless ENV['SLACK_QA_CHANNEL'].to_s.strip.empty?

  raise ArgumentError, "Please provide SLACK_QA_CHANNEL"
end

#require_ssh_tunnel!Object



277
278
279
280
281
# File 'lib/gitlab/qa/runtime/env.rb', line 277

def require_ssh_tunnel!
  %w[TUNNEL_SSH_PRIVATE_KEY TUNNEL_SERVER_HOSTNAME TUNNEL_SSH_USER].each do |env_key|
    raise ArgumentError, "Environment variable #{env_key} must be set to run tunnel specs" unless ENV.key?(env_key)
  end
end

#run_idObject



180
181
182
# File 'lib/gitlab/qa/runtime/env.rb', line 180

def run_id
  @run_id ||= "gitlab-qa-run-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}-#{SecureRandom.hex(4)}"
end

#skip_pull?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'lib/gitlab/qa/runtime/env.rb', line 290

def skip_pull?
  enabled?(ENV['QA_SKIP_PULL'], default: false)
end

#variablesObject



216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/gitlab/qa/runtime/env.rb', line 216

def variables
  vars = {}

  ENV_VARIABLES.each do |name, attribute|
    # Variables that are overridden in the environment take precedence
    # over the defaults specified by the QA runtime.
    value = env_value_if_defined(name) || send(attribute) # rubocop:disable GitlabSecurity/PublicSend
    vars[name] = value if value
  end

  vars
end