2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-01-03 18:57:55 -05:00
|
|
|
module Projects
|
|
|
|
module Settings
|
2017-01-23 17:19:39 -05:00
|
|
|
class CiCdController < Projects::ApplicationController
|
2020-09-30 17:10:09 -04:00
|
|
|
include RunnerSetupScripts
|
|
|
|
|
2020-11-10 19:08:58 -05:00
|
|
|
NUMBER_OF_RUNNERS_PER_PAGE = 20
|
|
|
|
|
2021-03-16 14:11:53 -04:00
|
|
|
layout 'project_settings'
|
2017-01-03 18:57:55 -05:00
|
|
|
before_action :authorize_admin_pipeline!
|
2021-12-10 10:10:24 -05:00
|
|
|
before_action :check_builds_available!
|
2018-03-22 10:31:41 -04:00
|
|
|
before_action :define_variables
|
2020-02-21 01:08:58 -05:00
|
|
|
before_action do
|
2020-04-01 08:08:00 -04:00
|
|
|
push_frontend_feature_flag(:ajax_new_deploy_token, @project)
|
2020-02-21 01:08:58 -05:00
|
|
|
end
|
2017-01-06 10:23:32 -05:00
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
helper_method :highlight_badge
|
|
|
|
|
2020-10-08 14:08:32 -04:00
|
|
|
feature_category :continuous_integration
|
|
|
|
|
2017-01-03 18:57:55 -05:00
|
|
|
def show
|
2020-09-28 14:09:40 -04:00
|
|
|
if Feature.enabled?(:ci_pipeline_triggers_settings_vue_ui, @project)
|
|
|
|
@triggers_json = ::Ci::TriggerSerializer.new.represent(
|
|
|
|
@project.triggers, current_user: current_user, project: @project
|
|
|
|
).to_json
|
|
|
|
end
|
2021-09-22 11:12:06 -04:00
|
|
|
|
2022-01-18 13:11:20 -05:00
|
|
|
if current_user.ci_owned_runners_cross_joins_fix_enabled?
|
2021-09-22 11:12:06 -04:00
|
|
|
render
|
2022-01-18 13:11:20 -05:00
|
|
|
else
|
|
|
|
# @assignable_runners is using ci_owned_runners
|
|
|
|
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336436') do
|
|
|
|
render
|
|
|
|
end
|
2021-09-22 11:12:06 -04:00
|
|
|
end
|
2018-03-22 10:31:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
Projects::UpdateService.new(project, current_user, update_params).tap do |service|
|
|
|
|
result = service.execute
|
|
|
|
if result[:status] == :success
|
2019-12-10 02:53:40 -05:00
|
|
|
flash[:toast] = _("Pipelines settings for '%{project_name}' were successfully updated.") % { project_name: @project.name }
|
2018-03-22 10:31:41 -04:00
|
|
|
|
|
|
|
run_autodevops_pipeline(service)
|
|
|
|
|
|
|
|
redirect_to project_settings_ci_cd_path(@project)
|
|
|
|
else
|
2019-04-24 09:44:12 -04:00
|
|
|
redirect_to project_settings_ci_cd_path(@project), alert: result[:message]
|
2018-03-22 10:31:41 -04:00
|
|
|
end
|
|
|
|
end
|
2017-01-18 14:50:15 -05:00
|
|
|
end
|
|
|
|
|
2018-01-04 13:13:30 -05:00
|
|
|
def reset_cache
|
|
|
|
if ResetProjectCacheService.new(@project, current_user).execute
|
2018-03-01 12:05:42 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :ok }
|
|
|
|
end
|
2018-01-04 13:13:30 -05:00
|
|
|
else
|
2018-03-01 12:05:42 -05:00
|
|
|
respond_to do |format|
|
|
|
|
format.json { head :bad_request }
|
|
|
|
end
|
2018-01-04 13:13:30 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-10 17:57:03 -04:00
|
|
|
def reset_registration_token
|
|
|
|
@project.reset_runners_token!
|
|
|
|
|
2019-12-10 02:53:40 -05:00
|
|
|
flash[:toast] = _("New runners registration token has been generated!")
|
2018-09-10 17:57:03 -04:00
|
|
|
redirect_to namespace_project_settings_ci_cd_path
|
|
|
|
end
|
|
|
|
|
2020-09-30 17:10:09 -04:00
|
|
|
def runner_setup_scripts
|
2021-03-31 08:08:55 -04:00
|
|
|
private_runner_setup_scripts
|
2020-09-30 17:10:09 -04:00
|
|
|
end
|
|
|
|
|
2017-01-18 14:50:15 -05:00
|
|
|
private
|
|
|
|
|
2020-10-08 11:08:17 -04:00
|
|
|
def highlight_badge(name, content, language = nil)
|
|
|
|
Gitlab::Highlight.highlight(name, content, language: language)
|
|
|
|
end
|
|
|
|
|
2018-03-22 10:31:41 -04:00
|
|
|
def update_params
|
2019-10-14 11:06:07 -04:00
|
|
|
params.require(:project).permit(*permitted_project_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def permitted_project_params
|
|
|
|
[
|
2018-03-22 10:31:41 -04:00
|
|
|
:runners_token, :builds_enabled, :build_allow_git_fetch,
|
|
|
|
:build_timeout_human_readable, :build_coverage_regex, :public_builds,
|
2020-11-03 10:09:05 -05:00
|
|
|
:auto_cancel_pending_pipelines, :ci_config_path, :auto_rollback_enabled,
|
2019-05-30 02:40:53 -04:00
|
|
|
auto_devops_attributes: [:id, :domain, :enabled, :deploy_strategy],
|
2020-10-20 02:09:03 -04:00
|
|
|
ci_cd_settings_attributes: [:default_git_depth, :forward_deployment_enabled]
|
2019-10-14 11:06:07 -04:00
|
|
|
].tap do |list|
|
|
|
|
list << :max_artifacts_size if can?(current_user, :update_max_artifacts_size, project)
|
|
|
|
end
|
2018-03-22 10:31:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_autodevops_pipeline(service)
|
|
|
|
return unless service.run_auto_devops_pipeline?
|
|
|
|
|
|
|
|
if @project.empty_repo?
|
2019-12-10 02:53:40 -05:00
|
|
|
flash[:notice] = _("This repository is currently empty. A new Auto DevOps pipeline will be created after a new file has been pushed to a branch.")
|
2018-03-22 10:31:41 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2020-02-14 16:09:08 -05:00
|
|
|
# rubocop:disable CodeReuse/Worker
|
2018-03-22 10:31:41 -04:00
|
|
|
CreatePipelineWorker.perform_async(project.id, current_user.id, project.default_branch, :web, ignore_skip_ci: true, save_on_errors: false)
|
2020-02-14 16:09:08 -05:00
|
|
|
# rubocop:enable CodeReuse/Worker
|
2019-12-10 02:53:40 -05:00
|
|
|
|
2021-10-28 08:10:22 -04:00
|
|
|
flash[:toast] = _("A new Auto DevOps pipeline has been created, go to the Pipelines page for details")
|
2018-03-22 10:31:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def define_variables
|
|
|
|
define_runners_variables
|
2018-10-30 04:49:26 -04:00
|
|
|
define_ci_variables
|
2018-03-22 10:31:41 -04:00
|
|
|
define_triggers_variables
|
|
|
|
define_badges_variables
|
|
|
|
define_auto_devops_variables
|
|
|
|
end
|
|
|
|
|
2017-01-18 14:50:15 -05:00
|
|
|
def define_runners_variables
|
2020-11-10 19:08:58 -05:00
|
|
|
@project_runners = @project.runners.ordered.page(params[:project_page]).per(NUMBER_OF_RUNNERS_PER_PAGE).with_tags
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2017-12-19 10:40:19 -05:00
|
|
|
@assignable_runners = current_user
|
2018-05-10 08:42:55 -04:00
|
|
|
.ci_owned_runners
|
2017-12-19 10:40:19 -05:00
|
|
|
.assignable_for(project)
|
|
|
|
.ordered
|
2020-11-10 19:08:58 -05:00
|
|
|
.page(params[:specific_page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
|
2021-04-22 08:09:49 -04:00
|
|
|
.with_tags
|
2017-12-19 10:40:19 -05:00
|
|
|
|
2021-04-22 08:09:49 -04:00
|
|
|
@shared_runners = ::Ci::Runner.instance_type.active.with_tags
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2017-01-03 18:57:55 -05:00
|
|
|
@shared_runners_count = @shared_runners.count(:all)
|
2017-10-04 07:59:51 -04:00
|
|
|
|
2021-04-22 08:09:49 -04:00
|
|
|
@group_runners = ::Ci::Runner.belonging_to_parent_group_of_project(@project.id).with_tags
|
2017-01-18 14:50:15 -05:00
|
|
|
end
|
|
|
|
|
2018-10-30 04:49:26 -04:00
|
|
|
def define_ci_variables
|
2018-03-13 16:57:42 -04:00
|
|
|
@variable = ::Ci::Variable.new(project: project)
|
2017-05-03 14:51:55 -04:00
|
|
|
.present(current_user: current_user)
|
|
|
|
@variables = project.variables.order_key_asc
|
|
|
|
.map { |variable| variable.present(current_user: current_user) }
|
2017-01-23 17:19:39 -05:00
|
|
|
end
|
|
|
|
|
2017-01-18 14:50:15 -05:00
|
|
|
def define_triggers_variables
|
2017-01-03 18:57:55 -05:00
|
|
|
@triggers = @project.triggers
|
2018-12-19 09:51:02 -05:00
|
|
|
.present(current_user: current_user)
|
2020-09-28 14:09:40 -04:00
|
|
|
|
2018-03-13 16:57:42 -04:00
|
|
|
@trigger = ::Ci::Trigger.new
|
2018-12-19 09:51:02 -05:00
|
|
|
.present(current_user: current_user)
|
2017-01-18 14:50:15 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def define_badges_variables
|
2021-05-04 08:10:04 -04:00
|
|
|
@ref = params[:ref] || @project.default_branch_or_main
|
2017-01-03 18:57:55 -05:00
|
|
|
|
2021-01-26 22:08:58 -05:00
|
|
|
@badges = [Gitlab::Ci::Badge::Pipeline::Status,
|
|
|
|
Gitlab::Ci::Badge::Coverage::Report]
|
2017-01-03 18:57:55 -05:00
|
|
|
|
|
|
|
@badges.map! do |badge|
|
|
|
|
badge.new(@project, @ref).metadata
|
|
|
|
end
|
|
|
|
end
|
2017-08-30 14:39:23 -04:00
|
|
|
|
|
|
|
def define_auto_devops_variables
|
|
|
|
@auto_devops = @project.auto_devops || ProjectAutoDevops.new
|
|
|
|
end
|
2017-01-03 18:57:55 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Projects::Settings::CiCdController.prepend_mod_with('Projects::Settings::CiCdController')
|