diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-09-04 17:17:36 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-09-04 21:55:26 +0900 |
commit | fa6b9acaf9759c58353f8407ff20a7d02b8edf92 (patch) | |
tree | 501f164216de208239c73889a39ef94e82019099 | |
parent | 3ae2038176b27673b06a040873fdbe19c94d67d3 (diff) | |
download | gitlab-ce-fa6b9acaf9759c58353f8407ff20a7d02b8edf92.tar.gz |
trigger_variables should consider trigger_request existstance always
-rw-r--r-- | app/models/ci/build.rb | 14 | ||||
-rw-r--r-- | app/presenters/ci/build_presenter.rb | 11 | ||||
-rw-r--r-- | app/views/projects/jobs/_sidebar.html.haml | 8 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 38 |
4 files changed, 54 insertions, 17 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index ba3156154ac..e4f579b7897 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -221,14 +221,24 @@ module Ci variables += user_variables variables += project.group.secret_variables_for(ref, project).map(&:to_runner_variable) if project.group variables += secret_variables(environment: environment) - variables += trigger_request.user_variables if trigger_request - variables += pipeline.variables.map(&:to_runner_variable) + variables += trigger_variables variables += pipeline.pipeline_schedule.job_variables if pipeline.pipeline_schedule variables += persisted_environment_variables if environment variables end + def trigger_variables + return [] unless trigger_request # or pipeline.trigger? + + @trigger_variables ||= + if pipeline.variables.any? # If it's swtiched to Ci::PipelineVariables + pipeline.variables.map(&:to_runner_variable) + else # else it's still using trigger_request.variables + trigger_request.user_variables # Deprecated + end + end + def merge_request return @merge_request if defined?(@merge_request) diff --git a/app/presenters/ci/build_presenter.rb b/app/presenters/ci/build_presenter.rb index 531ccd39cf2..c495c3f39bb 100644 --- a/app/presenters/ci/build_presenter.rb +++ b/app/presenters/ci/build_presenter.rb @@ -17,16 +17,5 @@ module Ci "Job is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}" end end - - def old_or_new_trigger_variables - return @old_or_new_trigger_variables if defined?(@old_or_new_trigger_variables) - - if build.pipeline.variables.any? - @old_or_new_trigger_variables = - build.pipeline.variables&.map { |v| { v.key => v.value } } &.reduce({}, :merge) - else - @old_or_new_trigger_variables = build.trigger_request.variables - end - end end end diff --git a/app/views/projects/jobs/_sidebar.html.haml b/app/views/projects/jobs/_sidebar.html.haml index f22de357e5f..43e23bb2200 100644 --- a/app/views/projects/jobs/_sidebar.html.haml +++ b/app/views/projects/jobs/_sidebar.html.haml @@ -46,14 +46,14 @@ %span.build-light-text Token: #{@build.trigger_request.trigger.short_token} - - if @build.old_or_new_trigger_variables + - if @build.trigger_variables.any? %p %button.btn.group.btn-group-justified.reveal-variables Reveal Variables %dl.js-build-variables.trigger-build-variables.hide - - @build.old_or_new_trigger_variables.each do |key, value| - %dt.js-build-variable.trigger-build-variable= key - %dd.js-build-value.trigger-build-value= value + - @build.trigger_variables.each do |trigger_variable| + %dt.js-build-variable.trigger-build-variable= trigger_variable[:key] + %dd.js-build-value.trigger-build-value= trigger_variable[:value] %div{ class: (@build.pipeline.stages_count > 1 ? "block" : "block-last") } %p diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 08d22f166e4..137c460cce8 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1690,6 +1690,44 @@ describe Ci::Build do end end + describe '#trigger_variables' do + let(:build) { create(:ci_build, pipeline: pipeline, trigger_request: trigger_request) } + let(:trigger) { create(:ci_trigger, project: project) } + let(:trigger_request) { create(:ci_trigger_request, pipeline: pipeline, trigger: trigger) } + + subject { build.trigger_variables } + + it { is_expected.to eq(true) } + + context 'when variable is stored in ci_pipeline_variables' do + let!(:pipeline_variable) { create(:ci_pipeline_variable, pipeline: pipeline) } + + context 'when pipeline is triggered by trigger API' do + it 'returns variables' do + is_expected.to eq([pipeline_variable.to_runner_variable]) + end + end + + context 'when pipeline is not triggered by trigger API' do + let(:build) { create(:ci_build, pipeline: pipeline) } + + it 'does not return variables' do + is_expected.to eq([]) + end + end + end + + context 'when variable is stored in ci_trigger_requests.variables' do + before do + trigger_request.update_attribute(:variables, { 'TRIGGER_KEY_1' => 'TRIGGER_VALUE_1' } ) + end + + it 'returns variables' do + is_expected.to eq(trigger_request.user_variables) + end + end + end + describe 'state transition: any => [:pending]' do let(:build) { create(:ci_build, :created) } |