Skip to main content
  1. 2024/
  2. Posts from May/

Working With Feature Flags in Gitlab

Wait… What’s that GitLab Feature Flag command again?

I keep forgetting how to launch the GitLab Console to look at feature flags in gitlab1.

Yes, I know, This is well documented already2

I figured FutureMe🐺™️ Someone else might appreciate me leaving myself a note.

If this helps someone else, YAY! That’s Awesome! I love being helpful!

docker-compose exec gitlab "gitlab-ctl" "reconfigure"

Open up the GitLab Rails console #

Docker-compose gitlab #

docker-compose exec gitlab "gitlab-rails" "console"

Inside a GitLab VM/Container #

gitlab-rails console

Enable or disable the feature #

After the Rails console session has started, run the Feature.enable or Feature.disable commands accordingly. The specific flag can be found in the feature’s documentation itself.

Enabling: #

To enable a feature #

Example using feature example_feature

Enabling a fictional feature flag: #

Feature.enable(:<feature flag>)
Feature.enable(:example_feature)

Disabling: #

To Disable a feature: #

Example using feature example_feature

Disabling a fictional feature flag: #

Feature.disable(<feature flag>)
Feature.disable(:example_feature)

Some feature flags can be enabled or disabled on a per project basis:

Example: #

Project-scoped feature enablement #

Enable the :example_feature
feature flag for project
1234:

Feature.enable(:<feature flag>, Project.find(<project id>))
Feature.enable(:example_feature, Project.find(1234))
irb(main):001:0> Feature.enable(:example_feature)
=> true

Feature.enable and Feature.disable Always return true.

( Even if the application doesn’t use the flag )

Check if a feature flag is enabled #

To check if a flag is enabled or disabled, use Feature.enabled? or Feature.disabled?.

For example, for a feature flag named example_feature that is already enabled:

Feature.enabled?(:example_feature)
=> true
Feature.disabled?(:example_feature)
=> false

View set feature flags #

You can view all GitLab administrator set feature flags:

Feature.all
=> [#<Flipper::Feature:198 name="my_feature", state=:on, enabled_gate_names=[:boolean], adapter=:memoizable>]

Nice output #

Feature.all.map {|f| [f.name, f.state]}

Unsetting a feature flag #

You can unset a feature flag so
GitLab falls back to the current defaults
Feature.remove(:example_feature)
=> true