summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-07-13 10:40:12 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2015-07-13 10:40:12 +0000
commit4841977167eee77bc81552957716ac9c140120d2 (patch)
tree867549b6a88bb505845d161eeaf571298684a7a0 /app
parentc48a043c0fee94a33ef0c3bc1d74c2a494ba71e9 (diff)
parent49ee28e1075f8c92b34933c934a4e1c6e37b41cd (diff)
downloadgitlab-ci-4841977167eee77bc81552957716ac9c140120d2.tar.gz
Merge branch 'build-types' into 'master'
Allow to specify flexible list of types in yaml First part of flexible pipeline build in GitLab CI Having following `.gitlab-ci.yml`: ``` 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" ``` GitLab CI 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. The UI (screenshots are not for above YAML): ![Screen_Shot_2015-07-10_at_15.56.26](https://gitlab.com/gitlab-org/gitlab-ci/uploads/1f714b73772cf0d44168fb8e20e35561/Screen_Shot_2015-07-10_at_15.56.26.png) ![Screen_Shot_2015-07-10_at_15.57.19](https://gitlab.com/gitlab-org/gitlab-ci/uploads/fc9f458f2ca517d923a4382466fa99eb/Screen_Shot_2015-07-10_at_15.57.19.png) TODO: - [x] Implement in CI - [x] Specs - [x] Changelog - [x] CI tests - [ ] Documentation /cc @vsizov @sytses @dzaporozhets See merge request !198
Diffstat (limited to 'app')
-rw-r--r--app/controllers/lints_controller.rb2
-rw-r--r--app/models/build.rb4
-rw-r--r--app/models/commit.rb84
-rw-r--r--app/services/create_commit_service.rb4
-rw-r--r--app/views/builds/_build.html.haml10
-rw-r--r--app/views/builds/show.html.haml2
-rw-r--r--app/views/commits/_commit.html.haml4
-rw-r--r--app/views/commits/show.html.haml6
-rw-r--r--app/views/lints/_create.html.haml48
9 files changed, 78 insertions, 86 deletions
diff --git a/app/controllers/lints_controller.rb b/app/controllers/lints_controller.rb
index 9d5f445..b6ff69c 100644
--- a/app/controllers/lints_controller.rb
+++ b/app/controllers/lints_controller.rb
@@ -10,8 +10,8 @@ class LintsController < ApplicationController
@error = "Please provide content of .gitlab-ci.yml"
else
@config_processor = GitlabCiYamlProcessor.new params[:content]
+ @types = @config_processor.types
@builds = @config_processor.builds
- @deploy_builds = @config_processor.deploy_builds
@status = true
end
rescue GitlabCiYamlProcessor::ValidationError => e
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..eea3653 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -93,30 +93,50 @@ 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
@builds_without_retry ||=
begin
@@ -127,33 +147,17 @@ class Commit < ActiveRecord::Base
end
end
- def retried_builds
- @retried_builds ||= (builds - builds_without_retry)
- end
+ def builds_without_retry_sorted
+ return builds_without_retry unless config_processor
- 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
+ job_types = config_processor.types
+ builds_without_retry.sort_by do |build|
+ [job_types.index(build.job_type) || -1, build.name || ""]
end
+ 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
+ def retried_builds
+ @retried_builds ||= (builds.order(id: :desc) - builds_without_retry)
end
def status
@@ -225,6 +229,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 +246,7 @@ class Commit < ActiveRecord::Base
private
def save_yaml_error(error)
+ return unless self.yaml_errors?
self.yaml_errors = error
save
end
diff --git a/app/services/create_commit_service.rb b/app/services/create_commit_service.rb
index f9d16a5..4ae1852 100644
--- a/app/services/create_commit_service.rb
+++ b/app/services/create_commit_service.rb
@@ -42,10 +42,6 @@ class CreateCommitService
commit.create_builds unless commit.builds.any?
- if commit.builds.empty?
- commit.create_deploy_builds
- end
-
commit
end
end
diff --git a/app/views/builds/_build.html.haml b/app/views/builds/_build.html.haml
index f2a340d..598f734 100644
--- a/app/views/builds/_build.html.haml
+++ b/app/views/builds/_build.html.haml
@@ -7,14 +7,8 @@
%strong Build ##{build.id}
%td
- - if build.commit.tag?
- Tag
- &middot;
- #{build.ref}
- - else
- Commit
- &middot;
- #{build.short_sha}
+ = build.job_type
+
%td
= build.name
.pull-right
diff --git a/app/views/builds/show.html.haml b/app/views/builds/show.html.haml
index 5ddaa3c..55ac8af 100644
--- a/app/views/builds/show.html.haml
+++ b/app/views/builds/show.html.haml
@@ -10,7 +10,7 @@
#up-build-trace
- if @commit.matrix?
%ul.nav.nav-tabs.append-bottom-10
- - @commit.builds_without_retry.each do |build|
+ - @commit.builds_without_retry_sorted.each do |build|
%li{class: ('active' if build == @build) }
= link_to build_url(build) do
%i{class: build_icon_css_class(build)}
diff --git a/app/views/commits/_commit.html.haml b/app/views/commits/_commit.html.haml
index e5068d2..7fae74e 100644
--- a/app/views/commits/_commit.html.haml
+++ b/app/views/commits/_commit.html.haml
@@ -1,6 +1,10 @@
%tr.build.alert{class: commit_status_alert_class(commit)}
%td.status
= commit.status
+ - if commit.running?
+ &middot;
+ = commit.job_type
+
%td.build-link
= link_to project_ref_commit_path(commit.project, commit.ref, commit.sha) do
diff --git a/app/views/commits/show.html.haml b/app/views/commits/show.html.haml
index b1b586c..d335754 100644
--- a/app/views/commits/show.html.haml
+++ b/app/views/commits/show.html.haml
@@ -68,14 +68,14 @@
%tr
%th Status
%th Build ID
- %th Trigger
+ %th Type
%th Name
%th Duration
%th Finished at
- if @project.coverage_enabled?
%th Coverage
%th
- = render @commit.builds_without_retry, controls: true
+ = render @commit.builds_without_retry_sorted, controls: true
- if @commit.retried_builds.any?
%h3
@@ -86,7 +86,7 @@
%tr
%th Status
%th Build ID
- %th Trigger
+ %th Type
%th Name
%th Duration
%th Finished at
diff --git a/app/views/lints/_create.html.haml b/app/views/lints/_create.html.haml
index 70b6f8c..f82b406 100644
--- a/app/views/lints/_create.html.haml
+++ b/app/views/lints/_create.html.haml
@@ -10,37 +10,23 @@
%th Parameter
%th Value
%tbody
- - @builds.each do |build|
- %tr
- %td Job - #{build[:name]}
- %td
- %pre
- = simple_format build[:script]
-
- %b Tag list:
- = build[:tags]
- %br
- %b Refs only:
- = build[:only] && build[:only].join(", ")
- %br
- %b Refs except:
- = build[:except] && build[:except].join(", ")
+ - @types.each do |type|
+ - @builds.select { |build| build[:type] == type }.each do |build|
+ %tr
+ %td #{type.capitalize} Job - #{build[:name]}
+ %td
+ %pre
+ = simple_format build[:script]
- - @deploy_builds.each do |build|
- %tr
- %td Deploy Job - #{build[:name]}
- %td
- %pre
- = simple_format build[:script]
-
- %b Tag list:
- = build[:tags]
- %br
- %b Refs only:
- = build[:only] && build[:only].join(", ")
- %br
- %b Refs except:
- = build[:except] && build[:except].join(", ")
+ %br
+ %b Tag list:
+ = build[:tags]
+ %br
+ %b Refs only:
+ = build[:only] && build[:only].join(", ")
+ %br
+ %b Refs except:
+ = build[:except] && build[:except].join(", ")
-else
%p
@@ -49,5 +35,5 @@
%i.icon-remove.incorrect-syntax
%b Error:
= @error
-
+
\ No newline at end of file