diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb
index 4c67ef621..f18cc7d46 100644
--- a/app/controllers/quality_analysis_controller.rb
+++ b/app/controllers/quality_analysis_controller.rb
@@ -72,18 +72,28 @@ class QualityAnalysisController < ApplicationController
end
end
- @console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
+ # 获取sonar output结果
+ console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
logger.info("@current_build_status is ==> #{@current_build_status}")
- d = @client.job.delete("#{job_name}") if jenkins_job == '200' && code != '201'
- logger.error("delete result ==> #{code}")
- if @current_build_status == "success"
- SonarError.create()
- end
- if qa.blank? && @current_build_status == "success"
- QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
- :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}")
+
+ # 两种情况需要删除job:
+ # 1/创建成功但是build失败则删除job
+ # 2/creat和build成功,调用sonar启动失败则删除job
+ # 错误信息存储需存到Trustie数据库,否则一旦job删除则无法获取这些信息
+ if jenkins_job == '200' && code != '201'
+ @client.job.delete("#{job_name}")
else
- qa.update_attribute(:sonar_version, version) unless qa.blank?
+ if @current_build_status == "failure"
+ @sonar_error = SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => console_build)
+ @client.job.delete("#{job_name}")
+ elsif @current_build_status == "success"
+ if qa.blank?
+ QualityAnalysis.create(:project_id => @project.id, :author_login => user_name, :rep_identifier => identifier,
+ :sonar_version => version, :path => path, :branch => branch, :language => language, :sonar_name => "#{user_name}:#{rep_id}")
+ else
+ qa.update_attribute(:sonar_version, version)
+ end
+ end
end
end
rescue => e
@@ -93,11 +103,18 @@ class QualityAnalysisController < ApplicationController
if @current_build_status == "success"
format.html{redirect_to project_quality_analysis_path(:project_id => @project.id, :resource_id => sonar_name, :branch => branch, :current_build_status => @current_build_status, :job_name => job_name)}
elsif @current_build_status == "failure"
- format.html
+ format.html{redirect_to error_list_project_quality_analysi_path(:project_id => @project.id, :job_name => job_name)}
end
end
end
+ def error_list
+ @error_list = SonarError.where(:jenkins_job_name => params[:job_name]).first
+ respond_to do |format|
+ format.html
+ end
+ end
+
# get language type
def swith_language_type language
if language == "c#"
diff --git a/app/models/sonar_error.rb b/app/models/sonar_error.rb
new file mode 100644
index 000000000..05fcfc5b9
--- /dev/null
+++ b/app/models/sonar_error.rb
@@ -0,0 +1,3 @@
+class SonarError < ActiveRecord::Base
+ attr_accessible :jenkins_job_name, :output, :project_id
+end
diff --git a/app/views/quality_analysis/create.html.erb b/app/views/quality_analysis/create.html.erb
index a0a9d7254..4f01fa2c8 100644
--- a/app/views/quality_analysis/create.html.erb
+++ b/app/views/quality_analysis/create.html.erb
@@ -3,9 +3,9 @@
本次分析失败,原因如下:
- <% if @current_build_status == "failure" %>
- <%= h @console_build.to_json %>
- <% elsif @build_console_result == false %>
+ <% if @build_console_result == false %>
分析超时
+ <% else %>
+ <%= h @sonar_error.to_json %>
<% end %>
\ No newline at end of file
diff --git a/app/views/quality_analysis/error_list.html.erb b/app/views/quality_analysis/error_list.html.erb
new file mode 100644
index 000000000..217990b13
--- /dev/null
+++ b/app/views/quality_analysis/error_list.html.erb
@@ -0,0 +1,11 @@
+
+
质量分析
+
+
+
本次分析失败,原因如下:
+ <% if @build_console_result == false %>
+ 分析超时
+ <% else %>
+ <%= h @error_list.to_json %>
+ <% end %>
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index bc9abeb35..0ef4c9fcb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -797,6 +797,7 @@ RedmineApp::Application.routes.draw do
match 'update_jenkins_job'
match 'edit'
match 'create'
+ get 'error_list'
end
end
# resources :files, :only => [:index, :new, :create] do
diff --git a/db/migrate/20160707031248_create_sonar_errors.rb b/db/migrate/20160707031248_create_sonar_errors.rb
new file mode 100644
index 000000000..c55caccce
--- /dev/null
+++ b/db/migrate/20160707031248_create_sonar_errors.rb
@@ -0,0 +1,11 @@
+class CreateSonarErrors < ActiveRecord::Migration
+ def change
+ create_table :sonar_errors do |t|
+ t.integer :project_id
+ t.string :jenkins_job_name
+ t.text :output
+
+ t.timestamps
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 3258f89c1..93dbba8a4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20160627090316) do
+ActiveRecord::Schema.define(:version => 20160707031248) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@@ -57,6 +57,18 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.integer "user_id", :null => false
end
+ create_table "apply_add_schools", :force => true do |t|
+ t.string "name"
+ t.string "province"
+ t.string "city"
+ t.string "address"
+ t.string "remarks"
+ t.integer "school_id"
+ t.integer "status", :default => 0
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "apply_homeworks", :force => true do |t|
t.integer "status"
t.integer "user_id"
@@ -1633,10 +1645,11 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
create_table "schools", :force => true do |t|
t.string "name"
t.string "province"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "logo_link"
t.string "pinyin"
+ t.integer "school_type", :default => 0
end
create_table "secdomains", :force => true do |t|
@@ -1725,6 +1738,14 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.integer "project_id"
end
+ create_table "sonar_errors", :force => true do |t|
+ t.integer "project_id"
+ t.string "jenkins_job_name"
+ t.text "output"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "ssos", :force => true do |t|
t.integer "user_id"
t.string "openid"
@@ -1849,8 +1870,18 @@ ActiveRecord::Schema.define(:version => 20160627090316) do
t.string "title"
t.text "description"
t.integer "user_id"
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "eng_name"
+ t.integer "syllabus_type"
+ t.integer "credit"
+ t.integer "hours"
+ t.integer "theory_hours"
+ t.integer "practice_hours"
+ t.string "applicable_major"
+ t.string "pre_course"
+ t.integer "visits", :default => 0
+ t.integer "des_status", :default => 0
end
add_index "syllabuses", ["user_id"], :name => "index_syllabuses_on_user_id"
diff --git a/spec/factories/sonar_errors.rb b/spec/factories/sonar_errors.rb
new file mode 100644
index 000000000..a5ed5485f
--- /dev/null
+++ b/spec/factories/sonar_errors.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+ factory :sonar_error do
+ project_id 1
+ jenkins_job_name "MyString"
+ output "MyText"
+ end
+end
diff --git a/spec/models/sonar_error_spec.rb b/spec/models/sonar_error_spec.rb
new file mode 100644
index 000000000..9aae8db29
--- /dev/null
+++ b/spec/models/sonar_error_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe SonarError, :type => :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end