diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 14:56:09 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 16:04:35 +0200 |
commit | efdf54f25a83462a750cacd4ea7919c7d38e67d1 (patch) | |
tree | e1823788941ac74352446c065a26b79eb22f985d /app/models | |
parent | d841ed56d39db1b33947b9b9c0291beaa7dcdd43 (diff) | |
download | gitlab-ci-efdf54f25a83462a750cacd4ea7919c7d38e67d1.tar.gz |
Allow to specify flexible list of types in yaml
```
types:
- test
- deploy
- notify
rspec:
script: "rspec"
rubocop:
script: "rubocop"
staging:
type: deploy
script: "echo deploy"
only:
- master
production:
type: deploy
script: "echo production"
only:
- tags
dockerhub:
type: notify
script: "curl http://docker/hub/web/hook"
downstream:
type: notify
script: "curl http://build/downstream/jobs"
```
This will trigger two test jobs in parallel, when finished it will trigged either staging or production, when finished it will trigger dockerhub and downstream in parallel.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/build.rb | 4 | ||||
-rw-r--r-- | app/models/commit.rb | 86 |
2 files changed, 49 insertions, 41 deletions
diff --git a/app/models/build.rb b/app/models/build.rb index 5e6522d..11bd967 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -111,8 +111,8 @@ class Build < ActiveRecord::Base WebHookService.new.build_end(build) end - if build.commit.success? && !build.deploy? - build.commit.create_deploy_builds + if build.commit.success? + build.commit.create_next_builds end project.execute_services(build) diff --git a/app/models/commit.rb b/app/models/commit.rb index e173ed4..c7584c6 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -93,67 +93,67 @@ class Commit < ActiveRecord::Base recipients.uniq end - def create_builds - return if skip_ci? + def job_type + return unless config_processor + job_types = builds_without_retry.select(&:active?).map(&:job_type) + config_processor.types.find { |job_type| job_types.include? job_type } + end - begin - builds_for_ref = config_processor.builds_for_ref(ref, tag) - rescue GitlabCiYamlProcessor::ValidationError => e - save_yaml_error(e.message) and return - rescue Exception => e - logger.error e.message + "\n" + e.backtrace.join("\n") - save_yaml_error("Undefined yaml error") and return - end + def create_builds_for_type(job_type) + return if skip_ci? + return unless config_processor - builds_for_ref.each do |build_attrs| + builds_attrs = config_processor.builds_for_type_and_ref(job_type, ref, tag) + builds_attrs.map do |build_attrs| builds.create!({ project: project, name: build_attrs[:name], commands: build_attrs[:script], tag_list: build_attrs[:tags], options: build_attrs[:options], - allow_failure: build_attrs[:allow_failure] + allow_failure: build_attrs[:allow_failure], + job_type: build_attrs[:type] }) end end + def create_next_builds + return if skip_ci? + return unless config_processor + + build_types = builds.group_by(&:job_type) + + config_processor.types.any? do |job_type| + !build_types.include?(job_type) && create_builds_for_type(job_type).present? + end + end + + def create_builds + return if skip_ci? + return unless config_processor + + config_processor.types.any? do |job_type| + create_builds_for_type(job_type).present? + end + end + def builds_without_retry + return unless config_processor @builds_without_retry ||= begin + job_types = config_processor.types grouped_builds = builds.group_by(&:name) - grouped_builds.map do |name, builds| + grouped_builds = grouped_builds.map do |name, builds| builds.sort_by(&:id).last end + grouped_builds.sort_by do |build| + [job_types.index(build.job_type), build.name] + end end end def retried_builds - @retried_builds ||= (builds - builds_without_retry) - end - - def create_deploy_builds - return if skip_ci? - - begin - deploy_builds_for_ref = config_processor.deploy_builds_for_ref(ref, tag) - rescue GitlabCiYamlProcessor::ValidationError => e - save_yaml_error(e.message) and return - rescue Exception => e - logger.error e.message + "\n" + e.backtrace.join("\n") - save_yaml_error("Undefined yaml error") and return - end - - deploy_builds_for_ref.each do |build_attrs| - builds.create!({ - project: project, - name: build_attrs[:name], - commands: build_attrs[:script], - tag_list: build_attrs[:tags], - options: build_attrs[:options], - allow_failure: build_attrs[:allow_failure], - deploy: true - }) - end + @retried_builds ||= (builds.order(id: :desc) - builds_without_retry) end def status @@ -225,6 +225,13 @@ class Commit < ActiveRecord::Base def config_processor @config_processor ||= GitlabCiYamlProcessor.new(push_data[:ci_yaml_file] || project.generated_yaml_config) + rescue GitlabCiYamlProcessor::ValidationError => e + save_yaml_error(e.message) + nil + rescue Exception => e + logger.error e.message + "\n" + e.backtrace.join("\n") + save_yaml_error("Undefined yaml error") + nil end def skip_ci? @@ -235,6 +242,7 @@ class Commit < ActiveRecord::Base private def save_yaml_error(error) + return unless self.yaml_errors? self.yaml_errors = error save end |