From 71a5d5a036a34a9b2cd257e6e6a105095ec89241 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 18 Sep 2015 17:28:09 +0200 Subject: [PATCH 1/2] Fail builds if no .gitlab-ci.yml is found --- CHANGELOG | 1 + app/models/ci/commit.rb | 2 +- spec/services/ci/create_commit_service_spec.rb | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a1b17e58156..4733b28e50d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -42,6 +42,7 @@ v 8.0.0 (unreleased) - Retrieving oauth token with LDAP credentials - Load Application settings from running database unless env var USE_DB=false - Added Drone CI integration (Kirill Zaitsev) + - Fail builds if no .gitlab-ci.yml is found - Refactored service API and added automatically service docs generator (Kirill Zaitsev) - Added web_url key project hook_attrs (Kirill Zaitsev) - Add ability to get user information by ID of an SSH key via the API diff --git a/app/models/ci/commit.rb b/app/models/ci/commit.rb index 23cd47dfe37..f102d0a7679 100644 --- a/app/models/ci/commit.rb +++ b/app/models/ci/commit.rb @@ -236,7 +236,7 @@ module Ci end def config_processor - @config_processor ||= Ci::GitlabCiYamlProcessor.new(push_data[:ci_yaml_file] || project.generated_yaml_config) + @config_processor ||= Ci::GitlabCiYamlProcessor.new(push_data[:ci_yaml_file]) rescue Ci::GitlabCiYamlProcessor::ValidationError => e save_yaml_error(e.message) nil diff --git a/spec/services/ci/create_commit_service_spec.rb b/spec/services/ci/create_commit_service_spec.rb index 38d9943765a..981caaa51e1 100644 --- a/spec/services/ci/create_commit_service_spec.rb +++ b/spec/services/ci/create_commit_service_spec.rb @@ -50,6 +50,19 @@ module Ci end end + it 'fails commits without .gitlab-ci.yml' do + result = service.execute(project, + ref: 'refs/heads/0_1', + before: '00000000', + after: '31das312', + ci_yaml_file: config, + commits: [ { message: 'Message'} ] + ) + expect(result).to be_persisted + expect(result.builds.any?).to be_falsey + expect(result.status).to eq('failed') + end + describe :ci_skip? do it "skips builds creation if there is [ci skip] tag in commit message" do commits = [{ message: "some message[ci skip]" }] From 8671343b65810b983d2c8ea37b3123abd620c093 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 18 Sep 2015 17:51:56 +0200 Subject: [PATCH 2/2] Rubocop fix --- spec/services/ci/create_commit_service_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/services/ci/create_commit_service_spec.rb b/spec/services/ci/create_commit_service_spec.rb index 981caaa51e1..84ab0a615dd 100644 --- a/spec/services/ci/create_commit_service_spec.rb +++ b/spec/services/ci/create_commit_service_spec.rb @@ -56,7 +56,7 @@ module Ci before: '00000000', after: '31das312', ci_yaml_file: config, - commits: [ { message: 'Message'} ] + commits: [ { message: 'Message' } ] ) expect(result).to be_persisted expect(result.builds.any?).to be_falsey