Commit 2b907f61 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Commits without .gitlab-ci.yml are marked as skipped

- Save detailed error when YAML syntax
parent a42d469a
...@@ -188,12 +188,15 @@ module Ci ...@@ -188,12 +188,15 @@ module Ci
end end
def config_processor def config_processor
return nil unless ci_yaml_file
@config_processor ||= Ci::GitlabCiYamlProcessor.new(ci_yaml_file, gl_project.path_with_namespace) @config_processor ||= Ci::GitlabCiYamlProcessor.new(ci_yaml_file, gl_project.path_with_namespace)
rescue Ci::GitlabCiYamlProcessor::ValidationError => e rescue Ci::GitlabCiYamlProcessor::ValidationError => e
save_yaml_error(e.message) save_yaml_error(e.message)
nil nil
rescue Psych::SyntaxError => e
save_yaml_error(e.message)
nil
rescue Exception => e rescue Exception => e
logger.error e.message + "\n" + e.backtrace.join("\n")
save_yaml_error("Undefined yaml error") save_yaml_error("Undefined yaml error")
nil nil
end end
......
...@@ -425,8 +425,12 @@ module Ci ...@@ -425,8 +425,12 @@ module Ci
end end
describe "Error handling" do describe "Error handling" do
it "fails to parse YAML" do
expect{GitlabCiYamlProcessor.new("invalid: yaml: test")}.to raise_error(Psych::SyntaxError)
end
it "indicates that object is invalid" do it "indicates that object is invalid" do
expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError) expect{GitlabCiYamlProcessor.new("invalid_yaml")}.to raise_error(GitlabCiYamlProcessor::ValidationError)
end end
it "returns errors if tags parameter is invalid" do it "returns errors if tags parameter is invalid" do
......
...@@ -100,7 +100,24 @@ module Ci ...@@ -100,7 +100,24 @@ module Ci
end end
it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do it "skips builds creation if there is [ci skip] tag in commit message and yaml is invalid" do
stub_ci_commit_yaml_file('invalid: file') stub_ci_commit_yaml_file('invalid: file: fiile')
commits = [{ message: message }]
commit = service.execute(project, user,
ref: 'refs/tags/0_1',
before: '00000000',
after: '31das312',
commits: commits
)
expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to be_nil
end
end
describe :config_processor do
it "skips builds creation if yaml is invalid" do
allow_any_instance_of(Ci::Commit).to receive(:git_commit_message) { "message" }
stub_ci_commit_yaml_file('invalid: file: file')
commits = [{ message: message }] commits = [{ message: message }]
commit = service.execute(project, user, commit = service.execute(project, user,
ref: 'refs/tags/0_1', ref: 'refs/tags/0_1',
...@@ -110,6 +127,7 @@ module Ci ...@@ -110,6 +127,7 @@ module Ci
) )
expect(commit.builds.any?).to be false expect(commit.builds.any?).to be false
expect(commit.status).to eq("skipped") expect(commit.status).to eq("skipped")
expect(commit.yaml_errors).to_not be_nil
end end
end end
......
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