challenge保存的时候向jenkins发送请求,生成pipeline片段

This commit is contained in:
huang 2017-04-12 10:35:22 +08:00
parent bd2cbd6793
commit ba0f5976f0
2 changed files with 31 additions and 20 deletions

View File

@ -24,30 +24,36 @@ class ChallengesController < ApplicationController
@challenge.position = challenge_count + 1
@challenge.shixun = @shixun
@challenge.user = User.current
if @challenge.save
if params[:sample][:input].length > 0
params[:sample][:input].each_with_index do |value, index|
unless (value == params[:sample][:output][index] && value.blank?)
ChallengeSample.create(:challenge_id => @challenge.id, :input => value, :output => params[:sample][:output][index])
ActiveRecord::Base.transaction do
if @challenge.save
if params[:sample][:input].length > 0
params[:sample][:input].each_with_index do |value, index|
unless (value == params[:sample][:output][index] && value.blank?)
ChallengeSample.create(:challenge_id => @challenge.id, :input => value, :output => params[:sample][:output][index])
end
end
end
end
if params[:program][:output].length > 0
params[:program][:output].each do |output|
TestSet.create(:challenge_id => @challenge.id, :input => nil, :output => output)
if params[:program][:output].length > 0
params[:program][:output].each do |output|
TestSet.create(:challenge_id => @challenge.id, :input => nil, :output => output)
end
end
end
unless params[:knowledge].blank?
params[:knowledge][:input].each do |input|
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
unless params[:knowledge].blank?
params[:knowledge][:input].each do |input|
ChallengeTag.create(:name => input, :challenge_id => @challenge.id)
end
end
# 向jenkins端发送请求构建pipeline片段
params = {:shixunType => "#{@challenge.evaluation_way.to_i}", :filePath => "#{@challenge.path}", :step => "#{@challenge.position}"}
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/generateScriptPerChallenge")
res = uri_exec uri, params
respond_to do |format|
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '创建成功!'}
end
else
respond_to do |format|
format.html { render :action => 'new' }
end
end
respond_to do |format|
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '创建成功!'}
end
else
respond_to do |format|
format.html { render :action => 'new' }
end
end
end

View File

@ -0,0 +1,5 @@
class AddScriptToChallenge < ActiveRecord::Migration
def change
add_column :challenges, :pipeline_script, :text
end
end