diff --git a/lib/ci/pipeline_creation/inputs/string_input.rb b/lib/ci/pipeline_creation/inputs/string_input.rb index bb5ca29efc8..7ea9746ade5 100644 --- a/lib/ci/pipeline_creation/inputs/string_input.rb +++ b/lib/ci/pipeline_creation/inputs/string_input.rb @@ -54,7 +54,7 @@ module Ci override :coerced_value def coerced_value(value) - super.to_s + value.to_s end end end diff --git a/spec/lib/ci/pipeline_creation/inputs/spec_inputs_spec.rb b/spec/lib/ci/pipeline_creation/inputs/spec_inputs_spec.rb index 6d6d97d9e43..18e0fd3a25f 100644 --- a/spec/lib/ci/pipeline_creation/inputs/spec_inputs_spec.rb +++ b/spec/lib/ci/pipeline_creation/inputs/spec_inputs_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require 'oj' require_relative Rails.root.join('lib/ci/pipeline_creation/inputs/spec_inputs.rb') RSpec.describe Ci::PipelineCreation::Inputs::SpecInputs, feature_category: :pipeline_composition do diff --git a/spec/lib/gitlab/ci/config/interpolation/inputs_spec.rb b/spec/lib/gitlab/ci/config/interpolation/inputs_spec.rb index ba23a6c8df7..c8dd2ad00a8 100644 --- a/spec/lib/gitlab/ci/config/interpolation/inputs_spec.rb +++ b/spec/lib/gitlab/ci/config/interpolation/inputs_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require 'oj' require_relative Rails.root.join('lib/gitlab/ci/config/interpolation/inputs.rb') RSpec.describe Gitlab::Ci::Config::Interpolation::Inputs, feature_category: :pipeline_composition do @@ -195,6 +196,16 @@ RSpec.describe Gitlab::Ci::Config::Interpolation::Inputs, feature_category: :pip expect(inputs.to_hash).to eq(foo: 'bar') end end + + context 'when a hash value is passed as string' do + let(:specs) { { test_input: { type: 'string' } } } + let(:args) { { test_input: '{"key": "value"}' } } + + it 'is valid and behaves like an unparsed string' do + expect(inputs).to be_valid + expect(inputs.to_hash).to eq(test_input: '{"key": "value"}') + end + end end describe 'number validation' do diff --git a/spec/requests/api/ci/pipelines_spec.rb b/spec/requests/api/ci/pipelines_spec.rb index c1025f34ca2..4fd0615d58f 100644 --- a/spec/requests/api/ci/pipelines_spec.rb +++ b/spec/requests/api/ci/pipelines_spec.rb @@ -889,10 +889,14 @@ RSpec.describe API::Ci::Pipelines, feature_category: :continuous_integration do { 'Content-Type' => 'application/x-www-form-urlencoded' } end + let(:transformed_values) do + inputs.transform_values { |value| value.is_a?(String) ? value : value.to_json } + end + subject(:post_request) do post api("/projects/#{project.id}/pipeline", user), headers: headers, - params: { ref: project.default_branch, inputs: inputs.transform_values(&:to_json) } + params: { ref: project.default_branch, inputs: transformed_values } end it_behaves_like 'creating a succesful pipeline' diff --git a/spec/requests/api/ci/triggers_spec.rb b/spec/requests/api/ci/triggers_spec.rb index 330e271d3a1..0311666f3ce 100644 --- a/spec/requests/api/ci/triggers_spec.rb +++ b/spec/requests/api/ci/triggers_spec.rb @@ -237,10 +237,14 @@ RSpec.describe API::Ci::Triggers, feature_category: :pipeline_composition do { 'Content-Type' => 'application/x-www-form-urlencoded' } end + let(:transformed_values) do + inputs.transform_values { |value| value.is_a?(String) ? value : value.to_json } + end + subject(:post_request) do post api("/projects/#{project.id}/ref/master/trigger/pipeline?token=#{token}"), headers: headers, - params: { ref: 'refs/heads/other-branch', inputs: inputs.transform_values(&:to_json) } + params: { ref: 'refs/heads/other-branch', inputs: transformed_values } end it_behaves_like 'creating a succesful pipeline'