summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-04 17:25:59 +0000
committerDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-04 17:25:59 +0000
commitc4f1bdd8ae3ec242ea1634b59c8731bee4ef804d (patch)
tree58cebf4042cf5fe5ff1a693e495023cd5647fb99
parentfeffb36dea7830deefd1e756fbe2a82301df2061 (diff)
parenta9f9fb35f99e0e0708834e3db203a6b904bd1e43 (diff)
downloadgitlab-ci-c4f1bdd8ae3ec242ea1634b59c8731bee4ef804d.tar.gz
Merge branch 'jobs_tabs' into 'master'
Deploy jobs Implements #153 ![joxi_screenshot_1425465268516](https://dev.gitlab.org/gitlab/gitlab-ci/uploads/23960cfff46ac6c7d1d0ded528917306/joxi_screenshot_1425465268516.png) See merge request !124
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/jobs_controller.rb3
-rw-r--r--app/models/build.rb1
-rw-r--r--app/models/commit.rb16
-rw-r--r--app/models/job.rb12
-rw-r--r--app/views/jobs/_deploy_job_edit.html.haml52
-rw-r--r--app/views/jobs/_edit.html.haml67
-rw-r--r--app/views/jobs/deploy_jobs.html.haml12
-rw-r--r--app/views/jobs/index.html.haml8
-rw-r--r--app/views/layouts/_nav_project.html.haml2
-rw-r--r--config/routes.rb6
-rw-r--r--db/migrate/20150226001835_add_job_type_to_job.rb6
-rw-r--r--db/schema.rb12
-rw-r--r--spec/models/commit_spec.rb19
-rw-r--r--spec/models/job_spec.rb22
15 files changed, 195 insertions, 44 deletions
diff --git a/CHANGELOG b/CHANGELOG
index afe4add..0c5973e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@ v7.9.0
- Fix bug about showing edit button on commit page if user does not have permissions
- Allow to pass description and tag list during Runner's registration
- Added api for project jobs
+ - Implementation of deploy jobs after all parallel jobs(tests).
v7.8.0
- Fix OAuth login with GitLab installed in relative URL
diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
index 20a72a3..7d029aa 100644
--- a/app/controllers/jobs_controller.rb
+++ b/app/controllers/jobs_controller.rb
@@ -9,6 +9,9 @@ class JobsController < ApplicationController
def index
end
+ def deploy_jobs
+ end
+
private
def project
diff --git a/app/models/build.rb b/app/models/build.rb
index fd1cec1..ce634c8 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -117,6 +117,7 @@ class Build < ActiveRecord::Base
WebHookService.new.build_end(build)
end
+ build.commit.run_deploy_job(build.ref)
project.execute_services(build)
if project.coverage_enabled?
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 729b614..e92af46 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -31,7 +31,7 @@ class Commit < ActiveRecord::Base
end
def last_build
- builds.last
+ builds.order(:id).last
end
def retry
@@ -97,13 +97,13 @@ class Commit < ActiveRecord::Base
end
def create_builds
- project.jobs.where(build_branches: true).active.map do |job|
+ project.jobs.where(build_branches: true).active.parallel.map do |job|
create_build_from_job(job)
end
end
def create_builds_for_tag(ref = '')
- project.jobs.where(build_tags: true).active.map do |job|
+ project.jobs.where(build_tags: true).active.parallel.map do |job|
create_build_from_job(job, ref)
end
end
@@ -132,6 +132,16 @@ class Commit < ActiveRecord::Base
@retried_builds ||= (builds - builds_without_retry)
end
+ def run_deploy_job(ref)
+ if success? && !last_build.job.deploy?
+ project.jobs.deploy.active.each do |job|
+ if job.run_for_ref?(ref)
+ create_build_from_job(job)
+ end
+ end
+ end
+ end
+
def status
if success?
'success'
diff --git a/app/models/job.rb b/app/models/job.rb
index c21fce7..6453def 100644
--- a/app/models/job.rb
+++ b/app/models/job.rb
@@ -21,4 +21,16 @@ class Job < ActiveRecord::Base
scope :active, ->() { where(active: true) }
scope :archived, ->() { where(active: false) }
+ scope :parallel, ->(){ where(job_type: "parallel") }
+ scope :deploy, ->(){ where(job_type: "deploy") }
+
+ validate :refs, length: { maximum: 100 }
+
+ def deploy?
+ job_type == "deploy"
+ end
+
+ def run_for_ref?(ref)
+ refs.blank? || refs.split(",").map{|ref| ref.strip}.include?(ref)
+ end
end
diff --git a/app/views/jobs/_deploy_job_edit.html.haml b/app/views/jobs/_deploy_job_edit.html.haml
new file mode 100644
index 0000000..28c1b77
--- /dev/null
+++ b/app/views/jobs/_deploy_job_edit.html.haml
@@ -0,0 +1,52 @@
+= nested_form_for @project, html: { class: 'form-horizontal' } do |f|
+ - if @project.errors.any?
+ #error_explanation
+ %p.lead= "#{pluralize(@project.errors.count, "error")} prohibited this project from being saved:"
+ .alert.alert-error
+ %ul
+ - @project.errors.full_messages.each do |msg|
+ %li= msg
+
+ = f.fields_for :jobs do |job_form|
+ - if job_form.object.job_type == "deploy" || job_form.object.new_record?
+
+ = job_form.hidden_field :job_type, value: "deploy"
+ .form-group
+ = f.label :name, 'Name', class: 'control-label'
+ .col-sm-10
+ = job_form.text_field :name, class: 'form-control', placeholder: "Staging"
+ .form-group
+ = label_tag :tag_list, class: 'control-label' do
+ Tags
+ .col-sm-10
+ = job_form.text_field :tag_list, class: 'form-control'
+ .help-block
+ You can setup jobs to only use runners with specific tags.
+ Leave blank if you want this job to use any runner
+
+ .form-group
+ = label_tag :refs, class: 'control-label' do
+ Refs
+ .col-sm-10
+ = job_form.text_field :refs, class: 'form-control', placeholder: "master, staging"
+ .help-block
+ You can specify git references to run deploy jobs. Accepts strings only
+
+ .form-group
+ = f.label :commands, 'Script', class: 'control-label'
+ .col-sm-10
+ = job_form.text_area :commands, class: 'form-control', rows: 10, placeholder: "bundle exec rake spec"
+ %p.light
+ All lines will be concatenated into one file and executed.
+ %br
+ If you change the working directory or the environment this will affect all following lines too.
+ %br
+ = link_to("Example job scripts", "https://gitlab.com/gitlab-org/gitlab-ci/tree/master/doc/examples")
+ = job_form.link_to_remove "Remove this job", class: 'btn btn-danger pull-right'
+ %hr
+ .clearfix
+ = f.link_to_add "Add a job", :jobs, class: 'btn btn-save pull-right'
+
+ .form-actions
+ = f.submit 'Save changes', class: 'btn btn-success'
+
diff --git a/app/views/jobs/_edit.html.haml b/app/views/jobs/_edit.html.haml
index d4e5948..6617446 100644
--- a/app/views/jobs/_edit.html.haml
+++ b/app/views/jobs/_edit.html.haml
@@ -8,40 +8,41 @@
%li= msg
= f.fields_for :jobs do |job_form|
- .form-group
- = f.label :name, 'Name', class: 'control-label'
- .col-sm-10
- = job_form.text_field :name, class: 'form-control', placeholder: "Ex. cucumber"
- .form-group
- = f.label :build_branches, 'Trigger', class: 'control-label'
- .col-sm-10
- .checkbox
- = f.label :build_branches, 'Builds commits', class: ''
- = job_form.check_box :build_branches
- .checkbox
- = f.label :build_tags, 'Build tags', class: ''
- = job_form.check_box :build_tags
- .form-group
- = label_tag :tag_list, class: 'control-label' do
- Tags
- .col-sm-10
- = job_form.text_field :tag_list, class: 'form-control'
- .help-block
- You can setup jobs to only use runners with specific tags.
- Leave blank if you want this job to use any runner
+ - if job_form.object.job_type == "parallel" || job_form.object.new_record?
+ .form-group
+ = f.label :name, 'Name', class: 'control-label'
+ .col-sm-10
+ = job_form.text_field :name, class: 'form-control', placeholder: "Ex. cucumber"
+ .form-group
+ = f.label :build_branches, 'Trigger', class: 'control-label'
+ .col-sm-10
+ .checkbox
+ = f.label :build_branches, 'Builds commits', class: ''
+ = job_form.check_box :build_branches
+ .checkbox
+ = f.label :build_tags, 'Build tags', class: ''
+ = job_form.check_box :build_tags
+ .form-group
+ = label_tag :tag_list, class: 'control-label' do
+ Tags
+ .col-sm-10
+ = job_form.text_field :tag_list, class: 'form-control'
+ .help-block
+ You can setup jobs to only use runners with specific tags.
+ Leave blank if you want this job to use any runner
- .form-group
- = f.label :commands, 'Script', class: 'control-label'
- .col-sm-10
- = job_form.text_area :commands, class: 'form-control', rows: 10, placeholder: "bundle exec rake spec"
- %p.light
- All lines will be concatenated into one file and executed.
- %br
- If you change the working directory or the environment this will affect all following lines too.
- %br
- = link_to("Example job scripts", "https://gitlab.com/gitlab-org/gitlab-ci/tree/master/doc/examples")
- = job_form.link_to_remove "Remove this job", class: 'btn btn-danger pull-right'
- %hr
+ .form-group
+ = f.label :commands, 'Script', class: 'control-label'
+ .col-sm-10
+ = job_form.text_area :commands, class: 'form-control', rows: 10, placeholder: "bundle exec rake spec"
+ %p.light
+ All lines will be concatenated into one file and executed.
+ %br
+ If you change the working directory or the environment this will affect all following lines too.
+ %br
+ = link_to("Example job scripts", "https://gitlab.com/gitlab-org/gitlab-ci/tree/master/doc/examples")
+ = job_form.link_to_remove "Remove this job", class: 'btn btn-danger pull-right'
+ %hr
.clearfix
= f.link_to_add "Add a job", :jobs, class: 'btn btn-save pull-right'
diff --git a/app/views/jobs/deploy_jobs.html.haml b/app/views/jobs/deploy_jobs.html.haml
new file mode 100644
index 0000000..a602b72
--- /dev/null
+++ b/app/views/jobs/deploy_jobs.html.haml
@@ -0,0 +1,12 @@
+%ul.nav.nav-tabs.append-bottom-20
+ %li
+ = link_to 'Test (run in parallel)', project_jobs_path(@project)
+ %li{class: "active"}
+ = link_to 'Deploy (run on success)', deploy_jobs_project_jobs_path(@project)
+
+
+%p.slead
+ Deploy jobs are scripts you want CI to run on succeeding all parallel builds
+
+
+= render 'deploy_job_edit'
diff --git a/app/views/jobs/index.html.haml b/app/views/jobs/index.html.haml
index bc3570e..f1b82af 100644
--- a/app/views/jobs/index.html.haml
+++ b/app/views/jobs/index.html.haml
@@ -1,3 +1,11 @@
+%ul.nav.nav-tabs.append-bottom-20
+ %li{class: "active"}
+ = link_to 'Test (run in parallel)', project_jobs_path(@project)
+ %li
+ = link_to 'Deploy (run on success)', deploy_jobs_project_jobs_path(@project)
+
+
+
.btn-group.pull-right
= link_to project_jobs_path(@project), class: "btn #{'active' unless params[:list]}" do
%i.icon-edit
diff --git a/app/views/layouts/_nav_project.html.haml b/app/views/layouts/_nav_project.html.haml
index 6c2c8a0..a1e221d 100644
--- a/app/views/layouts/_nav_project.html.haml
+++ b/app/views/layouts/_nav_project.html.haml
@@ -16,7 +16,7 @@
= link_to project_runners_path(@project) do
%i.icon-cog
Runners
- = nav_link path: 'jobs#index' do
+ = nav_link path: ['jobs#index', 'jobs#deploy_jobs'] do
= link_to project_jobs_path(@project) do
%i.icon-code
Jobs
diff --git a/config/routes.rb b/config/routes.rb
index d1ba2c9..62e0665 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -49,7 +49,11 @@ Rails.application.routes.draw do
end
resources :runners, only: [:index, :edit, :update, :destroy]
- resources :jobs, only: [:index]
+ resources :jobs, only: [:index] do
+ collection do
+ get :deploy_jobs
+ end
+ end
end
resource :user_sessions do
diff --git a/db/migrate/20150226001835_add_job_type_to_job.rb b/db/migrate/20150226001835_add_job_type_to_job.rb
new file mode 100644
index 0000000..0153c87
--- /dev/null
+++ b/db/migrate/20150226001835_add_job_type_to_job.rb
@@ -0,0 +1,6 @@
+class AddJobTypeToJob < ActiveRecord::Migration
+ def change
+ add_column :jobs, :job_type, :string, default: 'parallel'
+ add_column :jobs, :refs, :string
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 8fdc4a0..5c22e68 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20150113001835) do
+ActiveRecord::Schema.define(version: 20150226001835) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -58,14 +58,16 @@ ActiveRecord::Schema.define(version: 20150113001835) do
add_index "commits", ["sha"], name: "index_commits_on_sha", using: :btree
create_table "jobs", force: true do |t|
- t.integer "project_id", null: false
+ t.integer "project_id", null: false
t.text "commands"
- t.boolean "active", default: true, null: false
+ t.boolean "active", default: true, null: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
- t.boolean "build_branches", default: true, null: false
- t.boolean "build_tags", default: false, null: false
+ t.boolean "build_branches", default: true, null: false
+ t.boolean "build_tags", default: false, null: false
+ t.string "job_type", default: "parallel"
+ t.string "refs"
end
add_index "jobs", ["project_id"], name: "index_jobs_on_project_id", using: :btree
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 40ccbe4..b1c1400 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -16,7 +16,7 @@ require 'spec_helper'
describe Commit do
let(:project) { FactoryGirl.create :project }
- let(:commit) { FactoryGirl.create :commit }
+ let(:commit) { FactoryGirl.create :commit, project: project }
let(:commit_with_project) { FactoryGirl.create :commit, project: project }
it { should belong_to(:project) }
@@ -159,4 +159,21 @@ describe Commit do
it { should eq(project.gitlab?) }
end
+
+ describe "run_deploy_job" do
+ before do
+ job = FactoryGirl.create :job, project: project
+ job1 = FactoryGirl.create :job, project: project
+ FactoryGirl.create :job, job_type: :deploy, project: project
+ FactoryGirl.create :build, commit: commit, status: :success, job: job
+ FactoryGirl.create :build, commit: commit, status: :success, job: job1
+ project.reload
+ end
+
+ it "creates new build for deploy" do
+ commit.run_deploy_job(commit.ref)
+
+ commit.builds.count.should == 3
+ end
+ end
end
diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb
new file mode 100644
index 0000000..342eab7
--- /dev/null
+++ b/spec/models/job_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+describe Job do
+ let(:project) { FactoryGirl.create :project }
+
+ it { should belong_to(:project) }
+ it { should have_many(:builds) }
+
+ describe "run_for_ref?" do
+ it "allows run for any ref if refs params is empty" do
+ job = FactoryGirl.create :job, project: project
+ job.run_for_ref?("anything").should be_true
+ end
+
+ it "allows run for any ref in refs params" do
+ job = FactoryGirl.create :job, project: project, refs: "master, staging"
+ job.run_for_ref?("master").should be_true
+ job.run_for_ref?("staging").should be_true
+ job.run_for_ref?("anything").should be_false
+ end
+ end
+end