diff --git a/app/controllers/quality_analysis_controller.rb b/app/controllers/quality_analysis_controller.rb index ae752f6b9..08ac4067f 100644 --- a/app/controllers/quality_analysis_controller.rb +++ b/app/controllers/quality_analysis_controller.rb @@ -2,7 +2,7 @@ class QualityAnalysisController < ApplicationController before_filter :find_project_by_project_id#, :except => [:getattachtype] before_filter :find_quality_analysis, :only => [:edit, :update_jenkins_job] before_filter :authorize - before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index] + before_filter :connect_jenkins, :only => [:create, :edit, :update_jenkins_job, :index, :delete] layout "base_projects" include ApplicationHelper include QualityAnalysisHelper @@ -84,7 +84,7 @@ class QualityAnalysisController < ApplicationController end # sonar 缓冲,取数据 - sleep(5) + sleep(3) # 获取sonar output结果 console_build = @client.job.get_console_output("#{job_name}", build_num = 0, start = 0, mode = 'text')["output"] @@ -152,11 +152,31 @@ class QualityAnalysisController < ApplicationController @gitlab_default_branch = @g.project(@project.gpid).default_branch end + # 删除的时候主要删除三方面数据:1/Trustie数据 2/jenkins数据 3/sonar数据 + # 如果只删除数据1,则新建的时候会有冲突 + def delete + begin + qa = QualityAnalysis.find(params[:id]) + rep_id = Repository.where(:project_id => @project.id, :identifier => qa.rep_identifier).first.try(:id) + job_name = "#{qa.author_login}-#{rep_id}" + logger.info("result: job_name ###################==>#{job_name}") + logger.info("result: @client.job ###################==>#{@client.job}") + + d_job = @client.job.delete(job_name) + logger.info("result: delete job ###################==>#{d_job}") + qa.delete + respond_to do |format| + format.html{redirect_to project_quality_analysis_path(:project_id => @project.id)} + end + rescue Exception => e + puts e + end + end + # 更新Jenkins job,主要包括相关配置文件参数的更新,Trustie平台数据的更新 def update_jenkins_job begin rep_id = Repository.where(:project_id => @project.id).first.try(:id) - logger.error("#############################===>666") sonar_name = @quality_analysis.sonar_name job_name = "#{@quality_analysis.author_login}-#{rep_id}" version = @quality_analysis.sonar_version @@ -223,7 +243,7 @@ class QualityAnalysisController < ApplicationController if key == "sqale_index" value = com["frmt_val"] else - value = com["val"].to_i + value = com["val"] end @ha.store(key,value) end @@ -260,9 +280,11 @@ class QualityAnalysisController < ApplicationController def connect_jenkins @gitlab_address = Redmine::Configuration['gitlab_address'] @jenkins_address = Redmine::Configuration['jenkins_address'] + jenkins_username = Redmine::Configuration['jenkins_username'] + jenkins_password = Redmine::Configuration['jenkins_password'] # connect jenkins - @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => "temp", :password => '123123') + @client = JenkinsApi::Client.new(:server_url => @jenkins_address, :username => jenkins_username, :password => jenkins_password) rescue => e logger.error("failed to connect Jenkins ==> #{e}") end diff --git a/app/views/quality_analysis/_result_list.html.erb b/app/views/quality_analysis/_result_list.html.erb index 3e2a7d373..d27ef6812 100644 --- a/app/views/quality_analysis/_result_list.html.erb +++ b/app/views/quality_analysis/_result_list.html.erb @@ -10,7 +10,7 @@