Commit 6e744f70 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'sh-fix-ci-lint-500-error' into 'master'

Fix 500 error in CI lint when included templates are an array

Closes #66605

See merge request gitlab-org/gitlab-ce!32232
parents eaae9cec bf505737
---
title: Fix 500 error in CI lint when included templates are an array
merge_request: 32232
author:
type: fixed
...@@ -2171,6 +2171,14 @@ include: ...@@ -2171,6 +2171,14 @@ include:
- template: Auto-DevOps.gitlab-ci.yml - template: Auto-DevOps.gitlab-ci.yml
``` ```
Multiple `include:template` files:
```yaml
include:
- template: Android-Fastlane.gitlab-ci.yml
- template: Auto-DevOps.gitlab-ci.yml
```
All [nested includes](#nested-includes) will be executed only with the permission of the user, All [nested includes](#nested-includes) will be executed only with the permission of the user,
so it is possible to use project, remote or template includes. so it is possible to use project, remote or template includes.
......
...@@ -26,6 +26,10 @@ module Gitlab ...@@ -26,6 +26,10 @@ module Gitlab
location.present? location.present?
end end
def invalid_location_type?
!location.is_a?(String)
end
def invalid_extension? def invalid_extension?
location.nil? || !::File.basename(location).match?(YAML_WHITELIST_EXTENSION) location.nil? || !::File.basename(location).match?(YAML_WHITELIST_EXTENSION)
end end
...@@ -71,7 +75,9 @@ module Gitlab ...@@ -71,7 +75,9 @@ module Gitlab
end end
def validate_location! def validate_location!
if invalid_extension? if invalid_location_type?
errors.push("Included file `#{location}` needs to be a string")
elsif invalid_extension?
errors.push("Included file `#{location}` does not have YAML extension!") errors.push("Included file `#{location}` does not have YAML extension!")
end end
end end
......
...@@ -41,6 +41,12 @@ describe Gitlab::Ci::Config::External::File::Base do ...@@ -41,6 +41,12 @@ describe Gitlab::Ci::Config::External::File::Base do
end end
describe '#valid?' do describe '#valid?' do
context 'when location is not a string' do
let(:location) { %w(some/file.txt other/file.txt) }
it { is_expected.not_to be_valid }
end
context 'when location is not a YAML file' do context 'when location is not a YAML file' do
let(:location) { 'some/file.txt' } let(:location) { 'some/file.txt' }
......
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