Skip to content

Create rake tasks to seed CI variables and project environments

Mireya Andres requested to merge ma/ci-variables-seeder into master

What does this MR do and why?

This MR sets up different rake tasks that populate a project/group/instance with CI variables and environments. It will be useful for frontend development as we start working on paginating and limiting the query for fetching and searching environments and CI variables.

There are three different kinds of CI Variables that we can fetch through the CI/CD settings: Instance CI Variables (through the admin settings), Group CI Variables (through the group settings), and Project CI Variables (through the project settings). Instance CI Variables do not have environment scopes associated with them.

Example MR where this rake task can be helpful: !113171 (merged)

IMPORTANT NOTE: The environment scope dropdown in the modal for creating CI variables works differently for groups and projects. There is a separate query that fetches environments for projects. For groups, the list of environments is based on whatever environments are associate with variables we get from the variables query.

Screenshots or screen recordings

CI Variables Environments
Screenshot_2023-03-02_at_15.44.32 Screenshot_2023-03-02_at_15.40.28

How to set up and validate locally

You can use the following commands to seed your project.

# Seed environments
# Uses a default of 10 for seed_count and `ENV_` for the prefix
bundle exec rake "gitlab:seed:project_environments[project_path, seed_count, prefix]"

# Seed CI variables for project
# Uses a default of 10 for seed_count, "*" for environment_scope, and `VAR_` for the prefix.
# If environment_scope is set to "unique", each variable will have its own unique environment
bundle exec rake "gitlab:seed:ci_variables_project[project_path, seed_count, environment_scope, prefix]"

# Seed CI variables for group
# Uses a default of 10 for seed_count, "*" for environment_scope, and `GROUP_VAR_` for the prefix.
# If environment_scope is set to "unique", each variable will have its own unique environment
bundle exec rake "gitlab:seed:ci_variables_group[group_name, seed_count, environment_scope, prefix]"

# Seed CI variables for instance
# Uses a default of 10 for seed_count, and `INSTANCE_VAR_` for the prefix.
bundle exec rake "gitlab:seed:ci_variables_instance[seed_count, prefix]"

To validate in the UI:

  1. To view variables, go to Settings > CI/CD of your project and expand the Variables section. You can enable the ci_variables_pages feature flag to add pagination to this page.
  2. To view project environments, go to Deployments > Environments.
  3. For both group and project, environments will show up in the Environment Scope dropdown in the modal for adding CI variables (click Add variable button in the CI Variables settings).

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Mireya Andres

Merge request reports