From bf50573710ca008081063338664ec8b47a87d059 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Mon, 26 Aug 2019 12:12:52 -0700 Subject: [PATCH] Fix 500 error in CI lint when included templates are an array Previously the following syntax would fail in the linter with an error 500: ``` include: template: - License-Management.gitlab-ci.yml - Dependency-Scanning.gitlab-ci.yml - SAST.gitlab-ci.yml ``` Now the error will call out specifically that the value is not a string. Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/66605 --- changelogs/unreleased/sh-fix-ci-lint-500-error.yml | 5 +++++ doc/ci/yaml/README.md | 8 ++++++++ lib/gitlab/ci/config/external/file/base.rb | 8 +++++++- spec/lib/gitlab/ci/config/external/file/base_spec.rb | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 changelogs/unreleased/sh-fix-ci-lint-500-error.yml diff --git a/changelogs/unreleased/sh-fix-ci-lint-500-error.yml b/changelogs/unreleased/sh-fix-ci-lint-500-error.yml new file mode 100644 index 00000000000..74d9f980d46 --- /dev/null +++ b/changelogs/unreleased/sh-fix-ci-lint-500-error.yml @@ -0,0 +1,5 @@ +--- +title: Fix 500 error in CI lint when included templates are an array +merge_request: 32232 +author: +type: fixed diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 7a60dedc206..0a1dcf2737b 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -2170,6 +2170,14 @@ include: - 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, so it is possible to use project, remote or template includes. diff --git a/lib/gitlab/ci/config/external/file/base.rb b/lib/gitlab/ci/config/external/file/base.rb index 2ffbb214a92..c56d33544ba 100644 --- a/lib/gitlab/ci/config/external/file/base.rb +++ b/lib/gitlab/ci/config/external/file/base.rb @@ -26,6 +26,10 @@ module Gitlab location.present? end + def invalid_location_type? + !location.is_a?(String) + end + def invalid_extension? location.nil? || !::File.basename(location).match?(YAML_WHITELIST_EXTENSION) end @@ -71,7 +75,9 @@ module Gitlab end 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!") end end diff --git a/spec/lib/gitlab/ci/config/external/file/base_spec.rb b/spec/lib/gitlab/ci/config/external/file/base_spec.rb index dd536a241bd..af995f4869a 100644 --- a/spec/lib/gitlab/ci/config/external/file/base_spec.rb +++ b/spec/lib/gitlab/ci/config/external/file/base_spec.rb @@ -41,6 +41,12 @@ describe Gitlab::Ci::Config::External::File::Base do end 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 let(:location) { 'some/file.txt' }