BigW Consortium Gitlab

Commit 9f7e5e45 by Lin Jen-Shin

Add back Pipeline#ci_yaml_file_path due to all the troubles

parent 60b8156a
......@@ -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
......
......@@ -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"))
......
......@@ -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
......
......@@ -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
......
......@@ -1179,7 +1179,7 @@ describe Ci::Build, :models do
{ key: 'CI_PROJECT_NAMESPACE', value: project.namespace.full_path, public: true },
{ key: 'CI_PROJECT_URL', value: project.web_url, public: true },
{ key: 'CI_PIPELINE_ID', value: pipeline.id.to_s, public: true },
{ key: 'CI_CONFIG_PATH', value: project.ci_config_file_for_pipeline, public: true },
{ key: 'CI_CONFIG_PATH', value: pipeline.ci_yaml_file_path, public: true },
{ key: 'CI_REGISTRY_USER', value: 'gitlab-ci-token', public: true },
{ key: 'CI_REGISTRY_PASSWORD', value: build.token, public: false },
{ key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }
......
......@@ -748,6 +748,28 @@ describe Ci::Pipeline, models: true do
end
end
describe '#ci_yaml_file_path' do
subject { pipeline.ci_yaml_file_path }
it 'returns the path from project' do
allow(pipeline.project).to receive(:ci_config_file) { 'custom/path' }
is_expected.to eq('custom/path')
end
it 'returns default when custom path is nil' do
allow(pipeline.project).to receive(:ci_config_file) { nil }
is_expected.to eq('.gitlab-ci.yml')
end
it 'returns default when custom path is empty' do
allow(pipeline.project).to receive(:ci_config_file) { '' }
is_expected.to eq('.gitlab-ci.yml')
end
end
describe '#ci_yaml_file' do
it 'reports error if the file is not found' do
allow(pipeline.project).to receive(:ci_config_file) { 'custom' }
......
......@@ -1493,30 +1493,6 @@ describe Project, models: true do
end
end
describe '#ci_config_file_for_pipeline' do
let(:project) { create(:empty_project) }
subject { project.ci_config_file_for_pipeline }
it 'returns the path from project' do
allow(project).to receive(:ci_config_file) { 'custom/path' }
is_expected.to eq('custom/path')
end
it 'returns default when custom path is nil' do
allow(project).to receive(:ci_config_file) { nil }
is_expected.to eq('.gitlab-ci.yml')
end
it 'returns default when custom path is empty' do
allow(project).to receive(:ci_config_file) { '' }
is_expected.to eq('.gitlab-ci.yml')
end
end
describe '#ci_config_file=' do
let(:project) { create(:empty_project) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment