Skip to content

Allow users to specify environment tier via .gitlab-ci.yml

Shinya Maeda requested to merge specify-environment-tier into master

What does this MR do?

In !55471 (merged), we've added the tier column to the environments table. This column is to specify the Deployment environment, which is one of production, staging, testing, development, or other.

In this MR, we allow users to specify the tier via .gitlab-ci.yml. We add a new key named environment:deployment_tier: in the .gitlab-ci.yml syntax:

For example, you can specify that customer-portal environment is production tier.

deploy-to-production:
  script: echo 'Deploy to production'
  environment:
    name: customer-portal
    deployment_tier: production 

In general, the tier is automatically set based on the environment:name:, but sometimes user puts an application codename (e.g. customer-portal) to an environment and an unexpected tier could be set. environment:deployment_tier is a complement in such case.

Related #300741 (closed)

Screenshots (strongly suggested)

Specify the environment tier in .gitlab-ci.yml

2021-03-10_13-46

Deployment job passed

2021-03-10_13-48

The tier is correctly reflected on the row

[2] pry(main)> project.environments.find_by_name('customer-portal').tier
  Environment Load (0.4ms)  SELECT "environments".* FROM "environments" WHERE "environments"."project_id" = $1 AND "environments"."name" = $2 LIMIT $3 /*application:console,line:/devkitkat/services/rails/cache/ruby/2.7.0/gems/activerecord-6.0.3.4/lib/active_record/connection_adapters/postgresql/database_statements.rb:98:in `exec_query'*/  [["project_id", 35], ["name", "customer-portal"], ["LIMIT", 1]]
=> "production"

Specify the unknown tier in .gitlab-ci.yml

2021-03-10_13-54

Show a proper error

2021-03-10_13-57

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Shinya Maeda

Merge request reports