add error system
This commit is contained in:
parent
ec32204809
commit
406d636aac
|
@ -26,14 +26,25 @@ class QualityAnalysisController < ApplicationController
|
|||
job_name = "#{user_name}-#{rep_id}"
|
||||
sonar_name = "#{user_name}:#{rep_id}"
|
||||
|
||||
# 考虑到历史数据:有些用户创建类job但是build失败,即sonar没有结果,这个时候需要把job删除,并且删掉quality_analyses表数据
|
||||
# 如果不要这句则需要迁移数据
|
||||
@sonar_address = Redmine::Configuration['sonar_address']
|
||||
projects_date = open(@sonar_address + "/api/projects/index").read
|
||||
arr = JSON.parse(projects_date).map {|m| m["nm"]} # eg: ["Hjqreturn:cc_rep", "Hjqreturn:putong", "Hjqreturn:sonar_rep2", "shitou:sonar_rep"]
|
||||
quality_an = QualityAnalysis.where(:sonar_name => sonar_name).first
|
||||
if @client.job.exists?(job_name) && QualityAnalysis.where(:sonar_name => sonar_name).select{|qa| arr.include?(qa.sonar_name)}.blank?
|
||||
logger.info("88888888888888888888")
|
||||
aa = @client.job.delete("#{job_name}")
|
||||
quality_an.delete unless quality_an.blank?
|
||||
end
|
||||
# Checks if the given job exists in Jenkins.
|
||||
unless @client.job.exists?(job_name)
|
||||
@g = Gitlab.client
|
||||
branch = params[:branch]
|
||||
language = swith_language_type(params[:language])
|
||||
path = params[:path].blank? ? "./" : params[:path]
|
||||
qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
|
||||
version = qa.nil? ? 1 : qa.sonar_version + 1
|
||||
# qa = QualityAnalysis.where(:project_id => @project.id, :author_login => user_name).first
|
||||
version = quality_an.nil? ? 1 : quality_an.sonar_version + 1
|
||||
properties = "sonar.projectKey=#{sonar_name}
|
||||
sonar.projectName=#{sonar_name}
|
||||
sonar.projectVersion=#{version}
|
||||
|
@ -73,7 +84,7 @@ class QualityAnalysisController < ApplicationController
|
|||
end
|
||||
|
||||
# 获取sonar output结果
|
||||
console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')
|
||||
console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"]
|
||||
logger.info("@current_build_status is ==> #{@current_build_status}")
|
||||
|
||||
# 两种情况需要删除job:
|
||||
|
@ -84,10 +95,13 @@ class QualityAnalysisController < ApplicationController
|
|||
@client.job.delete("#{job_name}")
|
||||
else
|
||||
if @current_build_status == "failure"
|
||||
@sonar_error = SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => console_build)
|
||||
reg_console = /Exception:.*?\r/.match(console_build)
|
||||
output = reg_console[0].gsub("\r", "") unless reg_console.nil?
|
||||
se = SonarError.where(:jenkins_job_name => job_name).first
|
||||
se.nil? ? SonarError.create(:project_id => @project.id, :jenkins_job_name => job_name, :output => output) : se.update_column(:output, output)
|
||||
@client.job.delete("#{job_name}")
|
||||
elsif @current_build_status == "success"
|
||||
if qa.blank?
|
||||
if quality_an.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
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
<% if @build_console_result == false %>
|
||||
分析超时
|
||||
<% else %>
|
||||
<%= h @error_list.to_json %>
|
||||
<%= h @error_list.output %>
|
||||
<% end %>
|
||||
</div>
|
Loading…
Reference in New Issue