🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# Enable and disable GitLab features deployed behind feature flags > 原文:[https://docs.gitlab.com/ee/administration/feature_flags.html](https://docs.gitlab.com/ee/administration/feature_flags.html) * [How to enable and disable features behind flags](#how-to-enable-and-disable-features-behind-flags) * [Start the GitLab Rails console](#start-the-gitlab-rails-console) * [Enable or disable the feature](#enable-or-disable-the-feature) # Enable and disable GitLab features deployed behind feature flags[](#enable-and-disable-gitlab-features-deployed-behind-feature-flags-core-only "Permalink") GitLab 采用[功能标记策略](../development/feature_flags/index.html)在开发的早期阶段部署功能,以便可以逐步推出它们. 在使它们永久可用之前,出于[多种原因](../development/feature_flags/process.html#when-to-use-feature-flags) ,可以将功能部署在标志的后面,例如: * 测试功能. * 在功能开发的早期阶段获得用户和客户的反馈. * 评估用户采用率. * 评估它如何影响 GitLab 的性能. * 在整个发行版中以较小的部分构建它. 标记后面的功能通常可以逐步推出: 1. 默认情况下,该功能开始禁用. 2. 该功能默认情况下处于启用状态. 3. 功能标记已删除. 可以启用和禁用这些功能,以允许或禁止用户使用它们. GitLab 管理员可以访问 GitLab Rails 控制台来完成此操作. 如果您使用了某个功能并发现了错误,不正常行为或错误,那么尽快向 GitLab [**提供反馈**](https://gitlab.com/gitlab-org/gitlab/-/issues/new?issue[title]=Docs - feature flag feedback: Feature Name&issue[description]=Describe the problem you've encountered. <!-- Don't edit below this line --> /label ~)非常重要,这样我们就可以在标记后改进或修复它. 当您将 GitLab 升级到早期版本时,功能标志状态可能会更改. **注意:请**注意,部署在功能标记后面的功能可能尚未准备好用于生产. 但是,禁用默认情况下已启用的已部署标志后面的功能也可能带来风险. 如果启用了它们,我们建议您保持原样. ## How to enable and disable features behind flags[](#how-to-enable-and-disable-features-behind-flags "Permalink") 每个功能都有其自己的标志,应使用该标志来启用和禁用它. 标志后面的每个功能的文档都包括一个部分,通知标志的状态以及启用或禁用标志的命令. ### Start the GitLab Rails console[](#start-the-gitlab-rails-console "Permalink") 启用或禁用标志后面的功能的第一件事是在 GitLab Rails 控制台上启动会话. 对于所有安装; ``` sudo gitlab-rails console ``` 对于源安装: ``` sudo -u git -H bundle exec rails console -e production ``` 有关详细信息,请参见[启动 Rails 控制台会话](troubleshooting/debug.html#starting-a-rails-console-session) . ### Enable or disable the feature[](#enable-or-disable-the-feature "Permalink") 一旦启动 Rails 控制台会话,请相应地运行`Feature.enable`或`Feature.disable`命令. 特定标志可以在功能文档中找到. 要启用功能,请运行: ``` Feature.enable(:<feature flag>) ``` 例如,启用证据收集: ``` Feature.enable(:release_evidence_collection) ``` 要禁用功能,请运行: ``` Feature.disable(:<feature flag>) ``` Example, to disable Evidence Collection: ``` Feature.disable(:release_evidence_collection) ``` 可以基于每个项目启用或禁用某些功能标志: ``` Feature.enable(:<feature flag>, Project.find(<project id>)) ``` 例如,要为项目`1234`启用[`:junit_pipeline_view`](../ci/junit_test_reports.html#enabling-the-junit-test-reports-feature-core-only)功能标记: ``` Feature.enable(:junit_pipeline_view, Project.find(1234)) ``` `Feature.enable`和`Feature.disable`始终返回`nil` ,这并不表示命令失败: ``` irb(main):001:0> Feature.enable(:release_evidence_collection) => nil ``` 要检查标志是启用还是禁用,可以使用`Feature.enabled?` 或`Feature.disabled?` : ``` Feature.enable(:release_evidence_collection) => nil Feature.enabled?(:release_evidence_collection) => true Feature.disabled?(:release_evidence_collection) => false ``` 功能就绪后,GitLab 将删除功能标志,启用和禁用该功能的选项将不再存在,并且该功能将在所有实例中可用.