From 07365e518330289149dd2135424c49fad19f401d Mon Sep 17 00:00:00 2001 From: Keith Pope Date: Fri, 5 Aug 2016 10:29:09 +0100 Subject: Add config option to project to allow custom .gitlab-ci.yml location --- app/controllers/projects/pipelines_settings_controller.rb | 2 +- app/models/ci/pipeline.rb | 10 +++++++++- app/models/project.rb | 13 +++++++++++++ app/views/projects/pipelines_settings/show.html.haml | 7 +++++++ 4 files changed, 30 insertions(+), 2 deletions(-) (limited to 'app') 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 @@ -32,6 +32,13 @@ = f.label :build_timeout_in_minutes, 'Timeout', class: 'label-light' = 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 -- cgit v1.2.1 From 6e0cf082e5a42520c844e779d09cf61b08ebaa11 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 16:26:58 +0800 Subject: Inline what it was before for the regexp and message --- app/models/project.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 916393db776..0601f7fb977 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -187,8 +187,8 @@ class Project < ActiveRecord::Base 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 }, + format: { without: /\.{2}/.freeze, + message: 'cannot include directory traversal.' }, length: { maximum: 255 }, allow_blank: true validates :name, -- cgit v1.2.1 From 468e8b55585d54b1f92f647e8a1932f22610889e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 18:17:53 +0800 Subject: Fix doc, test, and form --- .../projects/pipelines_settings/_show.html.haml | 8 ++ .../projects/pipelines_settings/show.html.haml | 87 ---------------------- 2 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 app/views/projects/pipelines_settings/show.html.haml (limited to 'app') diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 580129ca809..2c2f0341e2a 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -45,6 +45,14 @@ Per job in minutes. If a job passes this threshold, it will be marked as failed = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'timeout'), target: '_blank' + %hr + .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. + %hr .form-group .checkbox diff --git a/app/views/projects/pipelines_settings/show.html.haml b/app/views/projects/pipelines_settings/show.html.haml deleted file mode 100644 index 25a991cdbfc..00000000000 --- a/app/views/projects/pipelines_settings/show.html.haml +++ /dev/null @@ -1,87 +0,0 @@ -- page_title "CI/CD Pipelines" - -.row.prepend-top-default - .col-lg-3.profile-settings-sidebar - %h4.prepend-top-0 - = page_title - .col-lg-9 - %h5.prepend-top-0 - Pipelines - = form_for @project, url: namespace_project_pipelines_settings_path(@project.namespace.becomes(Namespace), @project), remote: true, authenticity_token: true do |f| - %fieldset.builds-feature - - unless @repository.gitlab_ci_yml - .form-group - %p Pipelines need to be configured before you can begin using Continuous Integration. - = link_to 'Get started with CI/CD Pipelines', help_page_path('ci/quick_start/README'), class: 'btn btn-info' - .form-group - %p Get recent application code using the following command: - .radio - = f.label :build_allow_git_fetch_false do - = f.radio_button :build_allow_git_fetch, 'false' - %strong git clone - %br - %span.descr Slower but makes sure you have a clean dir before every build - .radio - = f.label :build_allow_git_fetch_true do - = f.radio_button :build_allow_git_fetch, 'true' - %strong git fetch - %br - %span.descr Faster - - .form-group - = f.label :build_timeout_in_minutes, 'Timeout', class: 'label-light' - = 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 / - = f.text_field :build_coverage_regex, class: 'form-control', placeholder: '\(\d+.\d+\%\) covered' - %span.input-group-addon / - %p.help-block - We will use this regular expression to find test coverage output in build trace. - Leave blank if you want to disable this feature - .bs-callout.bs-callout-info - %p Below are examples of regex for existing tools: - %ul - %li - Simplecov (Ruby) - - %code \(\d+.\d+\%\) covered - %li - pytest-cov (Python) - - %code \d+\%\s*$ - %li - phpunit --coverage-text --colors=never (PHP) - - %code ^\s*Lines:\s*\d+.\d+\% - %li - gcovr (C/C++) - - %code ^TOTAL.*\s+(\d+\%)$ - %li - tap --coverage-report=text-summary (Node.js) - - %code ^Statements\s*:\s*([^%]+) - - .form-group - .checkbox - = f.label :public_builds do - = f.check_box :public_builds - %strong Public pipelines - .help-block Allow everyone to access pipelines for Public and Internal projects - - .form-group.append-bottom-default - = f.label :runners_token, "Runners token", class: 'label-light' - = f.text_field :runners_token, class: "form-control", placeholder: 'xEeFCaDAB89' - %p.help-block The secure token used to checkout project. - - = f.submit 'Save changes', class: "btn btn-save" - -%hr - -.row.prepend-top-default - = render partial: 'badge', collection: @badges -- cgit v1.2.1 From 02ff4381979a5148cc17f7b6ea023fd4a1a5bffe Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 18:18:06 +0800 Subject: Try to report where the file should be --- app/services/ci/create_pipeline_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 942145c4a8c..4f35255fb53 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -33,7 +33,7 @@ module Ci unless pipeline.config_processor unless pipeline.ci_yaml_file - return error('Missing .gitlab-ci.yml file') + return error("Missing #{pipeline.ci_yaml_file_path} file") end return error(pipeline.yaml_errors, save: save_on_errors) end -- cgit v1.2.1 From 0d5e6536e7c18d839b1c1da0807aa90ba5be3e06 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 28 Jun 2017 18:29:14 +0800 Subject: Fix the test and implement missing update --- app/models/ci/pipeline.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 23b641c334d..3a514718ca8 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -327,6 +327,8 @@ module Ci @ci_yaml_file = begin project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path) rescue + self.yaml_errors = + "Failed to load CI/CD config file at #{ci_yaml_file_path}" nil end end -- cgit v1.2.1 From 17ba052f5c9d7c390b350469d15ffc674a943b07 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 30 Jun 2017 15:23:46 +0800 Subject: Update wordings, allow only full path, add tests --- app/models/ci/pipeline.rb | 9 +++++---- app/models/project.rb | 14 ++++++-------- app/views/projects/pipelines_settings/_show.html.haml | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 57bf5a8a4c5..12986e5781e 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -343,10 +343,11 @@ module Ci 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') + if project.ci_config_file.blank? + '.gitlab-ci.yml' + else + project.ci_config_file + end end def environments diff --git a/app/models/project.rb b/app/models/project.rb index 507dffde18b..5374aca7701 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -187,7 +187,7 @@ class Project < ActiveRecord::Base validates :creator, presence: true, on: :create validates :description, length: { maximum: 2000 }, allow_blank: true validates :ci_config_file, - format: { without: /\.{2}/.freeze, + format: { without: /\.{2}/, message: 'cannot include directory traversal.' }, length: { maximum: 255 }, allow_blank: true @@ -222,7 +222,6 @@ 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 has_many :uploads, as: :model, dependent: :destroy @@ -527,6 +526,11 @@ class Project < ActiveRecord::Base import_data&.destroy end + def ci_config_file=(value) + # Strip all leading slashes so that //foo -> foo + super(value&.sub(%r{\A/+}, '')) + end + def import_url=(value) return super(value) unless Gitlab::UrlSanitizer.valid?(value) @@ -1484,10 +1488,4 @@ class Project < ActiveRecord::Base raise ex 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 2c2f0341e2a..4b3efd12e08 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -47,11 +47,11 @@ %hr .form-group - = f.label :ci_config_file, 'Custom CI Config File', class: 'label-light' + = 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. + The path to CI config file. Default to .gitlab-ci.yml + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-file'), target: '_blank' %hr .form-group -- cgit v1.2.1 From 057c3c4e31df9dc8b1866b185dbf6d89e2751e3c Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 30 Jun 2017 16:14:48 +0800 Subject: Introduce CI_CONFIG_PATH --- app/models/ci/pipeline.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 12986e5781e..6905ab9ea23 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -391,7 +391,8 @@ module Ci def predefined_variables [ - { key: 'CI_PIPELINE_ID', value: id.to_s, public: true } + { key: 'CI_PIPELINE_ID', value: id.to_s, public: true }, + { key: 'CI_CONFIG_PATH', value: ci_yaml_file_path, public: true } ] end -- cgit v1.2.1 From d7c32c5870ff7122122d0fc75ed8a04a0818251e Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 02:00:50 +0800 Subject: Fix various descriptions given the feedback --- app/views/projects/pipelines_settings/_show.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index 4b3efd12e08..c9c8bd2610b 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -50,7 +50,7 @@ = 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 - The path to CI config file. Default to .gitlab-ci.yml + The path to CI config file. Defaults to .gitlab-ci.yml = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-file'), target: '_blank' %hr -- cgit v1.2.1 From 63bf2457e40ffd465d9a5aeee9b26b1c82432f9d Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:08:30 +0800 Subject: Follow feedback on the merge request --- app/models/ci/pipeline.rb | 16 ++++------------ app/models/project.rb | 8 ++++++++ app/models/repository.rb | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 6905ab9ea23..a38c63e9e91 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -330,10 +330,10 @@ module Ci return @ci_yaml_file if defined?(@ci_yaml_file) @ci_yaml_file = begin - project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path) - rescue + project.repository.gitlab_ci_yml_for(sha) + rescue Rugged::ReferenceError, GRPC::NotFound self.yaml_errors = - "Failed to load CI/CD config file at #{ci_yaml_file_path}" + "Failed to load CI/CD config file at #{project.ci_config_file_for_pipeline}" nil end end @@ -342,14 +342,6 @@ module Ci yaml_errors.present? end - def ci_yaml_file_path - if project.ci_config_file.blank? - '.gitlab-ci.yml' - else - project.ci_config_file - end - end - def environments builds.where.not(environment: nil).success.pluck(:environment).uniq end @@ -392,7 +384,7 @@ module Ci def predefined_variables [ { key: 'CI_PIPELINE_ID', value: id.to_s, public: true }, - { key: 'CI_CONFIG_PATH', value: ci_yaml_file_path, public: true } + { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true } ] end diff --git a/app/models/project.rb b/app/models/project.rb index 1513402132b..381e9067ad1 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -526,6 +526,14 @@ class Project < ActiveRecord::Base import_data&.destroy end + def ci_config_file_for_pipeline + if ci_config_file.blank? + '.gitlab-ci.yml' + else + ci_config_file + end + end + def ci_config_file=(value) # Strip all leading slashes so that //foo -> foo super(value&.sub(%r{\A/+}, '')) diff --git a/app/models/repository.rb b/app/models/repository.rb index 10b429c707e..0b06807e292 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1078,8 +1078,8 @@ class Repository blob_data_at(sha, '.gitlab/route-map.yml') end - def gitlab_ci_yml_for(sha, path = '.gitlab-ci.yml') - blob_data_at(sha, path) + def gitlab_ci_yml_for(sha) + blob_data_at(sha, project.ci_config_file_for_pipeline) end private -- cgit v1.2.1 From 8a0cd7dd1560c78fd1cd9fda363dc73bf8ee2010 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:22:10 +0800 Subject: Also remove null character --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') diff --git a/app/models/project.rb b/app/models/project.rb index 381e9067ad1..5298348b74d 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -536,7 +536,7 @@ class Project < ActiveRecord::Base def ci_config_file=(value) # Strip all leading slashes so that //foo -> foo - super(value&.sub(%r{\A/+}, '')) + super(value&.sub(%r{\A/+}, '')&.delete("\0")) end def import_url=(value) -- cgit v1.2.1 From 4d9c2bad369d510877dff719d94a5f98b1ee4dfe Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Tue, 4 Jul 2017 03:22:19 +0800 Subject: Fix config path --- app/models/ci/pipeline.rb | 2 +- app/services/ci/create_pipeline_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index a38c63e9e91..dd6fbfbd01b 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -331,7 +331,7 @@ module Ci @ci_yaml_file = begin project.repository.gitlab_ci_yml_for(sha) - rescue Rugged::ReferenceError, GRPC::NotFound + rescue Rugged::ReferenceError, GRPC::NotFound, GRPC::Internal self.yaml_errors = "Failed to load CI/CD config file at #{project.ci_config_file_for_pipeline}" nil diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index 4f35255fb53..b95c26560ae 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -33,7 +33,7 @@ module Ci unless pipeline.config_processor unless pipeline.ci_yaml_file - return error("Missing #{pipeline.ci_yaml_file_path} file") + return error("Missing #{project.ci_config_file_for_pipeline} file") end return error(pipeline.yaml_errors, save: save_on_errors) end -- cgit v1.2.1 From 9f7e5e45df9b7d99b97e40d1c08250925a408875 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Jul 2017 20:04:53 +0800 Subject: Add back Pipeline#ci_yaml_file_path due to all the troubles --- app/models/ci/pipeline.rb | 14 +++++++++++--- app/models/project.rb | 8 -------- app/models/repository.rb | 4 ++-- app/services/ci/create_pipeline_service.rb | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) (limited to 'app') diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index dd6fbfbd01b..759fdb4bf4c 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -326,14 +326,22 @@ module Ci end end + def ci_yaml_file_path + if project.ci_config_file.blank? + '.gitlab-ci.yml' + else + project.ci_config_file + end + end + def ci_yaml_file return @ci_yaml_file if defined?(@ci_yaml_file) @ci_yaml_file = begin - project.repository.gitlab_ci_yml_for(sha) + project.repository.gitlab_ci_yml_for(sha, ci_yaml_file_path) rescue Rugged::ReferenceError, GRPC::NotFound, GRPC::Internal self.yaml_errors = - "Failed to load CI/CD config file at #{project.ci_config_file_for_pipeline}" + "Failed to load CI/CD config file at #{ci_yaml_file_path}" nil end end @@ -384,7 +392,7 @@ module Ci def predefined_variables [ { key: 'CI_PIPELINE_ID', value: id.to_s, public: true }, - { key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true } + { key: 'CI_CONFIG_PATH', value: ci_yaml_file_path, public: true } ] end diff --git a/app/models/project.rb b/app/models/project.rb index 5298348b74d..edc95980729 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -526,14 +526,6 @@ class Project < ActiveRecord::Base import_data&.destroy end - def ci_config_file_for_pipeline - if ci_config_file.blank? - '.gitlab-ci.yml' - else - ci_config_file - end - end - def ci_config_file=(value) # Strip all leading slashes so that //foo -> foo super(value&.sub(%r{\A/+}, '')&.delete("\0")) diff --git a/app/models/repository.rb b/app/models/repository.rb index 0b06807e292..10b429c707e 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1078,8 +1078,8 @@ class Repository blob_data_at(sha, '.gitlab/route-map.yml') end - def gitlab_ci_yml_for(sha) - blob_data_at(sha, project.ci_config_file_for_pipeline) + def gitlab_ci_yml_for(sha, path = '.gitlab-ci.yml') + blob_data_at(sha, path) end private diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index b95c26560ae..4f35255fb53 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -33,7 +33,7 @@ module Ci unless pipeline.config_processor unless pipeline.ci_yaml_file - return error("Missing #{project.ci_config_file_for_pipeline} file") + return error("Missing #{pipeline.ci_yaml_file_path} file") end return error(pipeline.yaml_errors, save: save_on_errors) end -- cgit v1.2.1 From 9f5ac179d1ca4819006c66ae385ba7153f6c7e4f Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Wed, 5 Jul 2017 20:11:01 +0800 Subject: Rename ci_config_file to ci_config_path --- app/controllers/projects/pipelines_settings_controller.rb | 2 +- app/models/ci/pipeline.rb | 4 ++-- app/models/project.rb | 6 +++--- app/views/projects/pipelines_settings/_show.html.haml | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb index c3c17afa025..bfc453215c8 100644 --- a/app/controllers/projects/pipelines_settings_controller.rb +++ b/app/controllers/projects/pipelines_settings_controller.rb @@ -23,7 +23,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, :auto_cancel_pending_pipelines, :ci_config_file + :public_builds, :auto_cancel_pending_pipelines, :ci_config_path ) end end diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 759fdb4bf4c..c5847dee7f7 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -327,10 +327,10 @@ module Ci end def ci_yaml_file_path - if project.ci_config_file.blank? + if project.ci_config_path.blank? '.gitlab-ci.yml' else - project.ci_config_file + project.ci_config_path end end diff --git a/app/models/project.rb b/app/models/project.rb index edc95980729..96400b07b18 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -186,7 +186,7 @@ class Project < ActiveRecord::Base # Validations validates :creator, presence: true, on: :create validates :description, length: { maximum: 2000 }, allow_blank: true - validates :ci_config_file, + validates :ci_config_path, format: { without: /\.{2}/, message: 'cannot include directory traversal.' }, length: { maximum: 255 }, @@ -526,7 +526,7 @@ class Project < ActiveRecord::Base import_data&.destroy end - def ci_config_file=(value) + def ci_config_path=(value) # Strip all leading slashes so that //foo -> foo super(value&.sub(%r{\A/+}, '')&.delete("\0")) end @@ -1025,7 +1025,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 + ci_config_path: ci_config_path } # Backward compatibility diff --git a/app/views/projects/pipelines_settings/_show.html.haml b/app/views/projects/pipelines_settings/_show.html.haml index c9c8bd2610b..0d1c97df3ca 100644 --- a/app/views/projects/pipelines_settings/_show.html.haml +++ b/app/views/projects/pipelines_settings/_show.html.haml @@ -47,11 +47,11 @@ %hr .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' + = f.label :ci_config_path, 'Custom CI config path', class: 'label-light' + = f.text_field :ci_config_path, class: 'form-control', placeholder: '.gitlab-ci.yml' %p.help-block The path to CI config file. Defaults to .gitlab-ci.yml - = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-file'), target: '_blank' + = link_to icon('question-circle'), help_page_path('user/project/pipelines/settings', anchor: 'custom-ci-config-path'), target: '_blank' %hr .form-group -- cgit v1.2.1