Merge branch '44059-specify-variables-when-executing-a-manual-pipeline-from-the-ui' into 'master'
Resolve "Specify variables when executing a manual pipeline from the UI" Closes #44059 See merge request gitlab-org/gitlab-ce!18440
This commit is contained in:
commit
58aa2d7f39
|
@ -1,6 +1,12 @@
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import NewBranchForm from '~/new_branch_form';
|
import NewBranchForm from '~/new_branch_form';
|
||||||
|
import setupNativeFormVariableList from '~/ci_variable_list/native_form_variable_list';
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
new NewBranchForm($('.js-new-pipeline-form')); // eslint-disable-line no-new
|
new NewBranchForm($('.js-new-pipeline-form')); // eslint-disable-line no-new
|
||||||
|
|
||||||
|
setupNativeFormVariableList({
|
||||||
|
container: $('.js-ci-variable-list-section'),
|
||||||
|
formField: 'variables_attributes',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -157,7 +157,7 @@ class Projects::PipelinesController < Projects::ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_params
|
def create_params
|
||||||
params.require(:pipeline).permit(:ref)
|
params.require(:pipeline).permit(:ref, variables_attributes: %i[key secret_value])
|
||||||
end
|
end
|
||||||
|
|
||||||
def pipeline
|
def pipeline
|
||||||
|
|
|
@ -32,6 +32,8 @@ module Ci
|
||||||
has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id'
|
has_many :auto_canceled_pipelines, class_name: 'Ci::Pipeline', foreign_key: 'auto_canceled_by_id'
|
||||||
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
|
has_many :auto_canceled_jobs, class_name: 'CommitStatus', foreign_key: 'auto_canceled_by_id'
|
||||||
|
|
||||||
|
accepts_nested_attributes_for :variables, reject_if: :persisted?
|
||||||
|
|
||||||
delegate :id, to: :project, prefix: true
|
delegate :id, to: :project, prefix: true
|
||||||
delegate :full_path, to: :project, prefix: true
|
delegate :full_path, to: :project, prefix: true
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@ module Ci
|
||||||
|
|
||||||
belongs_to :pipeline
|
belongs_to :pipeline
|
||||||
|
|
||||||
|
alias_attribute :secret_value, :value
|
||||||
|
|
||||||
validates :key, uniqueness: { scope: :pipeline_id }
|
validates :key, uniqueness: { scope: :pipeline_id }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,7 @@ module Ci
|
||||||
ignore_skip_ci: ignore_skip_ci,
|
ignore_skip_ci: ignore_skip_ci,
|
||||||
save_incompleted: save_on_errors,
|
save_incompleted: save_on_errors,
|
||||||
seeds_block: block,
|
seeds_block: block,
|
||||||
|
variables_attributes: params[:variables_attributes],
|
||||||
project: project,
|
project: project,
|
||||||
current_user: current_user)
|
current_user: current_user)
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
- breadcrumb_title "Pipelines"
|
- breadcrumb_title "Pipelines"
|
||||||
- page_title = s_("Pipeline|Run Pipeline")
|
- page_title = s_("Pipeline|Run Pipeline")
|
||||||
|
- settings_link = link_to _('CI/CD settings'), project_settings_ci_cd_path(@project)
|
||||||
|
|
||||||
%h3.page-title
|
%h3.page-title
|
||||||
= s_("Pipeline|Run Pipeline")
|
= s_("Pipeline|Run Pipeline")
|
||||||
|
@ -8,17 +9,26 @@
|
||||||
= form_for @pipeline, as: :pipeline, url: project_pipelines_path(@project), html: { id: "new-pipeline-form", class: "form-horizontal js-new-pipeline-form js-requires-input" } do |f|
|
= form_for @pipeline, as: :pipeline, url: project_pipelines_path(@project), html: { id: "new-pipeline-form", class: "form-horizontal js-new-pipeline-form js-requires-input" } do |f|
|
||||||
= form_errors(@pipeline)
|
= form_errors(@pipeline)
|
||||||
.form-group
|
.form-group
|
||||||
= f.label :ref, s_('Pipeline|Run on'), class: 'control-label'
|
.col-sm-12
|
||||||
.col-sm-10
|
= f.label :ref, s_('Pipeline|Create for')
|
||||||
= hidden_field_tag 'pipeline[ref]', params[:ref] || @project.default_branch
|
= hidden_field_tag 'pipeline[ref]', params[:ref] || @project.default_branch
|
||||||
= dropdown_tag(params[:ref] || @project.default_branch,
|
= dropdown_tag(params[:ref] || @project.default_branch,
|
||||||
options: { toggle_class: 'js-branch-select wide git-revision-dropdown-toggle',
|
options: { toggle_class: 'js-branch-select wide git-revision-dropdown-toggle',
|
||||||
filter: true, dropdown_class: "dropdown-menu-selectable git-revision-dropdown", placeholder: s_("Pipeline|Search branches"),
|
filter: true, dropdown_class: "dropdown-menu-selectable git-revision-dropdown", placeholder: s_("Pipeline|Search branches"),
|
||||||
data: { selected: params[:ref] || @project.default_branch, field_name: 'pipeline[ref]' } })
|
data: { selected: params[:ref] || @project.default_branch, field_name: 'pipeline[ref]' } })
|
||||||
.help-block
|
.help-block
|
||||||
= s_("Pipeline|Existing branch name, tag")
|
= s_("Pipeline|Existing branch name or tag")
|
||||||
|
|
||||||
|
.col-sm-12.prepend-top-10.js-ci-variable-list-section
|
||||||
|
%label
|
||||||
|
= s_('Pipeline|Variables')
|
||||||
|
%ul.ci-variable-list
|
||||||
|
= render 'ci/variables/variable_row', form_field: 'pipeline', only_key_value: true
|
||||||
|
.help-block
|
||||||
|
= (s_("Pipeline|Specify variable values to be used in this run. The values specified in %{settings_link} will be used by default.") % {settings_link: settings_link}).html_safe
|
||||||
|
|
||||||
.form-actions
|
.form-actions
|
||||||
= f.submit s_('Pipeline|Run pipeline'), class: 'btn btn-success', tabindex: 3
|
= f.submit s_('Pipeline|Create pipeline'), class: 'btn btn-success js-variables-save-button', tabindex: 3
|
||||||
= link_to 'Cancel', project_pipelines_path(@project), class: 'btn btn-default pull-right'
|
= link_to 'Cancel', project_pipelines_path(@project), class: 'btn btn-default pull-right'
|
||||||
|
|
||||||
-# haml-lint:disable InlineJavaScript
|
-# haml-lint:disable InlineJavaScript
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Enable specifying variables when executing a manual pipeline
|
||||||
|
merge_request: 18440
|
||||||
|
author:
|
||||||
|
type: changed
|
|
@ -14,7 +14,8 @@ module Gitlab
|
||||||
trigger_requests: Array(@command.trigger_request),
|
trigger_requests: Array(@command.trigger_request),
|
||||||
user: @command.current_user,
|
user: @command.current_user,
|
||||||
pipeline_schedule: @command.schedule,
|
pipeline_schedule: @command.schedule,
|
||||||
protected: @command.protected_ref?
|
protected: @command.protected_ref?,
|
||||||
|
variables_attributes: Array(@command.variables_attributes)
|
||||||
)
|
)
|
||||||
|
|
||||||
@pipeline.set_config_source
|
@pipeline.set_config_source
|
||||||
|
|
|
@ -7,7 +7,7 @@ module Gitlab # rubocop:disable Naming/FileName
|
||||||
:origin_ref, :checkout_sha, :after_sha, :before_sha,
|
:origin_ref, :checkout_sha, :after_sha, :before_sha,
|
||||||
:trigger_request, :schedule,
|
:trigger_request, :schedule,
|
||||||
:ignore_skip_ci, :save_incompleted,
|
:ignore_skip_ci, :save_incompleted,
|
||||||
:seeds_block
|
:seeds_block, :variables_attributes
|
||||||
) do
|
) do
|
||||||
include Gitlab::Utils::StrongMemoize
|
include Gitlab::Utils::StrongMemoize
|
||||||
|
|
||||||
|
|
|
@ -517,16 +517,31 @@ describe 'Pipelines', :js do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates a new pipeline' do
|
it 'creates a new pipeline' do
|
||||||
expect { click_on 'Run pipeline' }
|
expect { click_on 'Create pipeline' }
|
||||||
.to change { Ci::Pipeline.count }.by(1)
|
.to change { Ci::Pipeline.count }.by(1)
|
||||||
|
|
||||||
expect(Ci::Pipeline.last).to be_web
|
expect(Ci::Pipeline.last).to be_web
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when variables are specified' do
|
||||||
|
it 'creates a new pipeline with variables' do
|
||||||
|
page.within '.ci-variable-row-body' do
|
||||||
|
fill_in "Input variable key", with: "key_name"
|
||||||
|
fill_in "Input variable value", with: "value"
|
||||||
|
end
|
||||||
|
|
||||||
|
expect { click_on 'Create pipeline' }
|
||||||
|
.to change { Ci::Pipeline.count }.by(1)
|
||||||
|
|
||||||
|
expect(Ci::Pipeline.last.variables.map { |var| var.slice(:key, :secret_value) })
|
||||||
|
.to eq [{ key: "key_name", secret_value: "value" }.with_indifferent_access]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'without gitlab-ci.yml' do
|
context 'without gitlab-ci.yml' do
|
||||||
before do
|
before do
|
||||||
click_on 'Run pipeline'
|
click_on 'Create pipeline'
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
|
it { expect(page).to have_content('Missing .gitlab-ci.yml file') }
|
||||||
|
@ -539,7 +554,7 @@ describe 'Pipelines', :js do
|
||||||
click_link 'master'
|
click_link 'master'
|
||||||
end
|
end
|
||||||
|
|
||||||
expect { click_on 'Run pipeline' }
|
expect { click_on 'Create pipeline' }
|
||||||
.to change { Ci::Pipeline.count }.by(1)
|
.to change { Ci::Pipeline.count }.by(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -557,7 +572,7 @@ describe 'Pipelines', :js do
|
||||||
it 'has field to add a new pipeline' do
|
it 'has field to add a new pipeline' do
|
||||||
expect(page).to have_selector('.js-branch-select')
|
expect(page).to have_selector('.js-branch-select')
|
||||||
expect(find('.js-branch-select')).to have_content project.default_branch
|
expect(find('.js-branch-select')).to have_content project.default_branch
|
||||||
expect(page).to have_content('Run on')
|
expect(page).to have_content('Create for')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,10 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
|
||||||
set(:user) { create(:user) }
|
set(:user) { create(:user) }
|
||||||
let(:pipeline) { Ci::Pipeline.new }
|
let(:pipeline) { Ci::Pipeline.new }
|
||||||
|
|
||||||
|
let(:variables_attributes) do
|
||||||
|
[{ key: 'first', secret_value: 'world' },
|
||||||
|
{ key: 'second', secret_value: 'second_world' }]
|
||||||
|
end
|
||||||
let(:command) do
|
let(:command) do
|
||||||
Gitlab::Ci::Pipeline::Chain::Command.new(
|
Gitlab::Ci::Pipeline::Chain::Command.new(
|
||||||
source: :push,
|
source: :push,
|
||||||
|
@ -15,7 +19,8 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
|
||||||
trigger_request: nil,
|
trigger_request: nil,
|
||||||
schedule: nil,
|
schedule: nil,
|
||||||
project: project,
|
project: project,
|
||||||
current_user: user)
|
current_user: user,
|
||||||
|
variables_attributes: variables_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:step) { described_class.new(pipeline, command) }
|
let(:step) { described_class.new(pipeline, command) }
|
||||||
|
@ -39,6 +44,8 @@ describe Gitlab::Ci::Pipeline::Chain::Build do
|
||||||
expect(pipeline.tag).to be false
|
expect(pipeline.tag).to be false
|
||||||
expect(pipeline.user).to eq user
|
expect(pipeline.user).to eq user
|
||||||
expect(pipeline.project).to eq project
|
expect(pipeline.project).to eq project
|
||||||
|
expect(pipeline.variables.map { |var| var.slice(:key, :secret_value) })
|
||||||
|
.to eq variables_attributes.map(&:with_indifferent_access)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets a valid config source' do
|
it 'sets a valid config source' do
|
||||||
|
|
|
@ -17,11 +17,13 @@ describe Ci::CreatePipelineService do
|
||||||
after: project.commit.id,
|
after: project.commit.id,
|
||||||
message: 'Message',
|
message: 'Message',
|
||||||
ref: ref_name,
|
ref: ref_name,
|
||||||
trigger_request: nil)
|
trigger_request: nil,
|
||||||
|
variables_attributes: nil)
|
||||||
params = { ref: ref,
|
params = { ref: ref,
|
||||||
before: '00000000',
|
before: '00000000',
|
||||||
after: after,
|
after: after,
|
||||||
commits: [{ message: message }] }
|
commits: [{ message: message }],
|
||||||
|
variables_attributes: variables_attributes }
|
||||||
|
|
||||||
described_class.new(project, user, params).execute(
|
described_class.new(project, user, params).execute(
|
||||||
source, trigger_request: trigger_request)
|
source, trigger_request: trigger_request)
|
||||||
|
@ -545,5 +547,19 @@ describe Ci::CreatePipelineService do
|
||||||
expect(pipeline.tag?).to be true
|
expect(pipeline.tag?).to be true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when pipeline variables are specified' do
|
||||||
|
let(:variables_attributes) do
|
||||||
|
[{ key: 'first', secret_value: 'world' },
|
||||||
|
{ key: 'second', secret_value: 'second_world' }]
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { execute_service(variables_attributes: variables_attributes) }
|
||||||
|
|
||||||
|
it 'creates a pipeline with specified variables' do
|
||||||
|
expect(subject.variables.map { |var| var.slice(:key, :secret_value) })
|
||||||
|
.to eq variables_attributes.map(&:with_indifferent_access)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue