summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKeith Pope <mute.pop3+gitlab@gmail.com>2016-08-05 10:29:09 +0100
committerKeith Pope <mute.pop3+gitlab@gmail.com>2016-10-08 12:30:47 +0100
commit07365e518330289149dd2135424c49fad19f401d (patch)
tree3a163231f4caa8f62c3fc5f4c0ca606c8ff92749 /app
parent28ca8502c254d5c3edfb7ece36fc365e7a715df0 (diff)
downloadgitlab-ce-07365e518330289149dd2135424c49fad19f401d.tar.gz
Add config option to project to allow custom .gitlab-ci.yml location
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/pipelines_settings_controller.rb2
-rw-r--r--app/models/ci/pipeline.rb10
-rw-r--r--app/models/project.rb13
-rw-r--r--app/views/projects/pipelines_settings/show.html.haml7
4 files changed, 30 insertions, 2 deletions
diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb
index 9136633b87a..d23418a9aa3 100644
--- a/app/controllers/projects/pipelines_settings_controller.rb
+++ b/app/controllers/projects/pipelines_settings_controller.rb
@@ -30,7 +30,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController
def update_params
params.require(:project).permit(
:runners_token, :builds_enabled, :build_allow_git_fetch, :build_timeout_in_minutes, :build_coverage_regex,
- :public_builds
+ :public_builds, :ci_config_file
)
end
end
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 2cf9892edc5..e6cd71a7bf2 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -218,14 +218,22 @@ module Ci
return @ci_yaml_file if defined?(@ci_yaml_file)
@ci_yaml_file ||= begin
- blob = project.repository.blob_at(sha, '.gitlab-ci.yml')
+ blob = project.repository.blob_at(sha, ci_yaml_file_path)
blob.load_all_data!(project.repository)
blob.data
rescue
+ self.yaml_errors = 'Failed to load CI config file'
nil
end
end
+ def ci_yaml_file_path
+ return '.gitlab-ci.yml' if project.ci_config_file.blank?
+ return project.ci_config_file if File.extname(project.ci_config_file.to_s) == '.yml'
+
+ File.join(project.ci_config_file || '', '.gitlab-ci.yml')
+ end
+
def environments
builds.where.not(environment: nil).success.pluck(:environment).uniq
end
diff --git a/app/models/project.rb b/app/models/project.rb
index 88e4bd14860..272c89798b6 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -154,6 +154,11 @@ class Project < ActiveRecord::Base
# Validations
validates :creator, presence: true, on: :create
validates :description, length: { maximum: 2000 }, allow_blank: true
+ validates :ci_config_file,
+ format: { without: Gitlab::Regex.directory_traversal_regex,
+ message: Gitlab::Regex.directory_traversal_regex_message },
+ length: { maximum: 255 },
+ allow_blank: true
validates :name,
presence: true,
length: { within: 0..255 },
@@ -182,6 +187,7 @@ class Project < ActiveRecord::Base
add_authentication_token_field :runners_token
before_save :ensure_runners_token
+ before_validation :clean_ci_config_file
mount_uploader :avatar, AvatarUploader
@@ -986,6 +992,7 @@ class Project < ActiveRecord::Base
visibility_level: visibility_level,
path_with_namespace: path_with_namespace,
default_branch: default_branch,
+ ci_config_file: ci_config_file
}
# Backward compatibility
@@ -1349,4 +1356,10 @@ class Project < ActiveRecord::Base
shared_projects.any?
end
+
+ def clean_ci_config_file
+ return unless self.ci_config_file
+ # Cleanup path removing leading/trailing slashes
+ self.ci_config_file = ci_config_file.gsub(/^\/+|\/+$/, '')
+ end
end
diff --git a/app/views/projects/pipelines_settings/show.html.haml b/app/views/projects/pipelines_settings/show.html.haml
index 8c7222bfe3d..25a991cdbfc 100644
--- a/app/views/projects/pipelines_settings/show.html.haml
+++ b/app/views/projects/pipelines_settings/show.html.haml
@@ -33,6 +33,13 @@
= f.number_field :build_timeout_in_minutes, class: 'form-control', min: '0'
%p.help-block per build in minutes
.form-group
+ = f.label :ci_config_file, 'Custom CI Config File', class: 'label-light'
+ = f.text_field :ci_config_file, class: 'form-control', placeholder: '.gitlab-ci.yml'
+ %p.help-block
+ Optionally specify the location of your CI config file E.g. my/path or my/path/.my-config.yml.
+ Default is to use '.gitlab-ci.yml' in the repository root.
+
+ .form-group
= f.label :build_coverage_regex, "Test coverage parsing", class: 'label-light'
.input-group
%span.input-group-addon /