diff options
author | Valery Sizov <vsv2711@gmail.com> | 2015-06-16 11:34:52 +0300 |
---|---|---|
committer | Valery Sizov <vsv2711@gmail.com> | 2015-06-16 11:34:52 +0300 |
commit | 20a1f80e599e680454f1ba6634f8227b593357a5 (patch) | |
tree | 4302fd7140f90aa23a0385ac4cd40972b46069d3 | |
parent | 232a64426422d32780e893cdc6938d4def2181b7 (diff) | |
download | gitlab-ci-20a1f80e599e680454f1ba6634f8227b593357a5.tar.gz |
invalid yaml handling
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | lib/gitlab_ci_yaml_processor.rb | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 7cebf35..1dc3e15 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -93,6 +93,7 @@ class Commit < ActiveRecord::Base def create_builds return if skip_ci? + return unless config_processor.valid? config_processor.builds_for_ref(ref, tag).each do |build_attrs| builds.create!({ @@ -120,6 +121,7 @@ class Commit < ActiveRecord::Base def create_deploy_builds return if skip_ci? + return unless config_processor.valid? config_processor.deploy_builds_for_ref(ref, tag).each do |build_attrs| builds.create!({ diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb index 9a69ca6..967146d 100644 --- a/lib/gitlab_ci_yaml_processor.rb +++ b/lib/gitlab_ci_yaml_processor.rb @@ -1,7 +1,10 @@ class GitlabCiYamlProcessor - attr_reader :before_script, :skip_refs + attr_reader :before_script, :skip_refs, :errors def initialize(config) + @errors = "" + @valid = true + @config = YAML.load(config).deep_symbolize_keys @before_script = @config[:before_script] || [] @@ -10,6 +13,14 @@ class GitlabCiYamlProcessor @jobs = @config.select{|key, value| value[:type] != "deploy"} @deploy_jobs = @config.select{|key, value| value[:type] == "deploy"} + + rescue Exception => e + @errors = e.message + @valid = false + end + + def valid? + @valid end def deploy_builds_for_ref(ref, tag = false) |