diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ff3f1c7d1..ea64d0397 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -929,10 +929,10 @@ class ProjectsController < ApplicationController end end - def uri_exec uri, params - res = Net::HTTP.post_form(uri, params).body - res = JSON.parse(res) - end + # def uri_exec uri, params + # # res = Net::HTTP.post_form(uri, params).body + # # res = JSON.parse(res) + # end # 开启实训项目,学生会fork一个项目并自动发送任务 def training_project_extend diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 4b1f10bb9..14a12009c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -268,7 +268,7 @@ module ApplicationHelper res = JSON.parse(res) rescue => e logger.error("failed to create challenge by 'generatePipelineScriptForChallenge'! #{e}") - raise("实训云平台繁忙(繁忙等级:84") + raise("实训云平台繁忙(繁忙等级:84)") end end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 0e99937bf..cbc995895 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,6 +1,7 @@ # status 控制实训的状态,0:未开启;1: 已开启(TPM); 2:已认证 # 繁忙等级参数:80发布实训失败,返回code为-1;81:实训开启的时候fork失败;83:j ;84:jenkins系统异常,post数据不成功 # 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败,没返回数据;89:重置链接jenkins返回失败 +# 116:challenge创建关卡的时候返回结果错误 class Shixun < ActiveRecord::Base attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication, :myshixun_count, :propaedeutics diff --git a/lib/tasks/jenkins_center.rake b/lib/tasks/jenkins_center.rake new file mode 100644 index 000000000..0437f74bb --- /dev/null +++ b/lib/tasks/jenkins_center.rake @@ -0,0 +1,38 @@ +namespace :jenkins do + namespace :myshixun do + desc "ping ce" + task :game_build => :environment do + 100.times do + puts "start" + game = Game.find_by_identifier('lhf7cyvjgmnq') + myshixun = game.myshixun + game_challenge = game.challenge + rep_identify = Repository.where(:myshixun_id => myshixun.id, :type => "Repository::Gitlab").first.try(:identifier) + gitlab_address = Redmine::Configuration['gitlab_address'] + gitUrl = gitlab_address.to_s+"/"+myshixun.owner.to_s+"/"+ rep_identify + "."+"git" + gitUrl = Base64.encode64(gitUrl) + taskId = game.id + jobName = "myshixun_#{myshixun.id}" + if game.status == 2 + game.update_attribute(:status, 0) + end + # 过关后重评不更新状态 + jenkins_shixuns = Redmine::Configuration['jenkins_shixuns'] + step = game_challenge.try(:position) + params = {:jobNameForInstance => "#{jobName}", :buildID => "#{taskId}", :step => "#{step}", :instanceGitURL => "#{gitUrl}", :instanceChallenge => "#{step}", :resubmit => nil} + uri = URI("#{jenkins_shixuns}/jenkins-exec/api/buildJobForInstance") + puts("post data time is #{Time.now}") + res = Net::HTTP.post_form(uri, params).body + res = JSON.parse(res) + puts("post data end time is #{Time.now}") + if (res && res['code'] != 0) + puts("error") + puts("current time is #{Time.now}") + end + puts("game over") + puts("waiting for 120s") + sleep(120); + end + end + end +end \ No newline at end of file diff --git a/lib/tasks/jenkins_publish.rake b/lib/tasks/jenkins_publish.rake new file mode 100644 index 000000000..e69de29bb