Commit abcd3574 authored by Markus Koller's avatar Markus Koller

Merge branch 'sh-handle-nil-services' into 'master'

Handle nil services error in external pipeline validation

See merge request gitlab-org/gitlab!76902
parents 0be890a7 cb1742b8
......@@ -113,7 +113,7 @@ module Gitlab
name: build[:name],
stage: build[:stage],
image: build.dig(:options, :image, :name),
services: build.dig(:options, :services)&.map { |service| service[:name] },
services: service_names(build),
script: [
build.dig(:options, :before_script),
build.dig(:options, :script),
......@@ -122,6 +122,14 @@ module Gitlab
}
end
def service_names(build)
services = build.dig(:options, :services)
return unless services
services.compact.map { |service| service[:name] }
end
def stages_attributes
command.yaml_processor_result.stages_attributes
end
......
......@@ -24,6 +24,7 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
second_stage_job_name:
stage: second_stage
services:
-
- postgres
before_script:
- echo 'first hello'
......@@ -142,6 +143,23 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Validate::External do
perform!
end
it 'returns expected payload' do
expect(::Gitlab::HTTP).to receive(:post) do |_url, params|
payload = Gitlab::Json.parse(params[:body])
builds = payload['builds']
expect(builds.count).to eq(2)
expect(builds[0]['services']).to be_nil
expect(builds[0]['stage']).to eq('first_stage')
expect(builds[0]['image']).to eq('hello_world')
expect(builds[1]['services']).to eq(['postgres'])
expect(builds[1]['stage']).to eq('second_stage')
expect(builds[1]['image']).to be_nil
end
perform!
end
end
context 'when EXTERNAL_VALIDATION_SERVICE_TOKEN is set' do
......
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