Commit 2c1838e7 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'mc/bug/use-pre-filled-variables-external-project-ci-config' into 'master'

Load config variables from external project

See merge request gitlab-org/gitlab!69646
parents c52fbb6d 6b5b4096
......@@ -191,7 +191,8 @@ class Projects::PipelinesController < Projects::ApplicationController
def config_variables
respond_to do |format|
format.json do
result = Ci::ListConfigVariablesService.new(@project, current_user).execute(params[:sha])
project = @project.uses_external_project_ci_config? ? @project.ci_config_external_project : @project
result = Ci::ListConfigVariablesService.new(project, current_user).execute(params[:sha])
result.nil? ? head(:no_content) : render(json: result)
end
......
......@@ -2549,6 +2549,10 @@ class Project < ApplicationRecord
ci_config_path.blank? || ci_config_path == Gitlab::FileDetector::PATTERNS[:gitlab_ci]
end
def uses_external_project_ci_config?
!!(ci_config_path =~ %r{@.+/.+})
end
def limited_protected_branches(limit)
protected_branches.limit(limit)
end
......@@ -2657,6 +2661,10 @@ class Project < ApplicationRecord
repository.gitlab_ci_yml_for(sha, ci_config_path_or_default)
end
def ci_config_external_project
Project.find_by_full_path(ci_config_path.split('@', 2).last)
end
def enabled_group_deploy_keys
return GroupDeployKey.none unless group
......
......@@ -171,9 +171,6 @@ variables:
You cannot set job-level variables to be pre-filled when you run a pipeline manually.
Pre-filled variables do not show up when the CI/CD configuration is [external to the project](settings.md#specify-a-custom-cicd-configuration-file).
See the [related issue](https://gitlab.com/gitlab-org/gitlab/-/issues/336184) for more details.
### Run a pipeline by using a URL query string
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/24146) in GitLab 12.5.
......
......@@ -1292,6 +1292,38 @@ RSpec.describe Projects::PipelinesController do
end
end
context 'when project uses external project ci config' do
let(:other_project) { create(:project) }
let(:sha) { 'master' }
let(:service) { ::Ci::ListConfigVariablesService.new(other_project, user) }
let(:ci_config) do
{
variables: {
KEY1: { value: 'val 1', description: 'description 1' }
},
test: {
stage: 'test',
script: 'echo'
}
}
end
before do
project.update!(ci_config_path: ".gitlab-ci.yml@#{other_project.full_path}")
synchronous_reactive_cache(service)
end
it 'returns other project config variables' do
expect(::Ci::ListConfigVariablesService).to receive(:new).with(other_project, anything).and_return(service)
get_config_variables
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['KEY1']).to eq({ 'value' => 'val 1', 'description' => 'description 1' })
end
end
private
def stub_gitlab_ci_yml_for_sha(sha, result)
......
......@@ -2548,7 +2548,7 @@ RSpec.describe Project, factory_default: :keep do
end
describe '#uses_default_ci_config?' do
let(:project) { build(:project)}
let(:project) { build(:project) }
it 'has a custom ci config path' do
project.ci_config_path = 'something_custom'
......@@ -2569,6 +2569,44 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#uses_external_project_ci_config?' do
subject(:uses_external_project_ci_config) { project.uses_external_project_ci_config? }
let(:project) { build(:project) }
context 'when ci_config_path is configured with external project' do
before do
project.ci_config_path = '.gitlab-ci.yml@hello/world'
end
it { is_expected.to eq(true) }
end
context 'when ci_config_path is nil' do
before do
project.ci_config_path = nil
end
it { is_expected.to eq(false) }
end
context 'when ci_config_path is configured with a file in the project' do
before do
project.ci_config_path = 'hello/world/gitlab-ci.yml'
end
it { is_expected.to eq(false) }
end
context 'when ci_config_path is configured with remote file' do
before do
project.ci_config_path = 'https://example.org/file.yml'
end
it { is_expected.to eq(false) }
end
end
describe '#latest_successful_build_for_ref' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:pipeline) { create_pipeline(project) }
......@@ -7049,6 +7087,15 @@ RSpec.describe Project, factory_default: :keep do
end
end
describe '#ci_config_external_project' do
subject(:ci_config_external_project) { project.ci_config_external_project }
let(:other_project) { create(:project) }
let(:project) { build(:project, ci_config_path: ".gitlab-ci.yml@#{other_project.full_path}") }
it { is_expected.to eq(other_project) }
end
describe '#enabled_group_deploy_keys' do
let_it_be(:project) { create(: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