启动任务相关接口

This commit is contained in:
huang 2017-02-19 14:39:15 +08:00
parent a43c5cdb2f
commit df66e6d60c
8 changed files with 1321 additions and 102 deletions

View File

@ -29,7 +29,7 @@ class ProjectsController < ApplicationController
menu_item :share, :only => :share
before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,
:view_homework_attaches,:join_project, :project_home]
:view_homework_attaches,:join_project, :project_home, :training_execute]
before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course]
before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches]
before_filter :require_admin, :only => [ :copy, :unarchive, :destroy, :calendar]
@ -804,6 +804,34 @@ class ProjectsController < ApplicationController
redirect_to admin_projects_url(:status => params[:status])
end
def training_project_execute
user_name = @project.owner.try(:login)
jobName = "#{user_name}_#{@project.id}"
pipeLine = Base64.encode64(@project.script)
params = {}
params["jobName"] = "#{jobName}"
params["pipeLine"] = "#{pipeLine}"
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/createJob")
uri_exec uri, params
# 返回成功信息job名存到数据库
end
def training_task_execute
taskId = params[:training_task_id]
jobName = @project.job_name
params = {}
params["jobName"] = "#{jobName}"
params["pipeLine"] = "#{pipeLine}"
uri = URI.parse("http://106.75.33.219:9999/jenkins-exec/api/createJob")
uri_exec uri, params
# 返回job执行信息哪一步成功错误原因
end
def uri_exec uri, params
res = Net::HTTP.post_form(uri, params)
res.body
end
# 资源库fork弹框
def forked_pop
@type = params[:type]

View File

@ -544,6 +544,8 @@ module ProjectsHelper
result = "manage_versions"
elsif user.allowed_to?(:manage_repository, @project)
result = "manage_repository"
elsif user.admin?
result = "training_task"
end
result
end

View File

@ -19,6 +19,9 @@
<% if User.current.allowed_to?(:manage_repository, @project) %>
<li><a href="javascript:void(0)" id="pro_st_tb_6" class="<%= show_memu == 'manage_repository' ? 'active' : ''%>" onclick="project_setting(6);">版本库</a></li>
<% end %>
<% if User.current.admin? %>
<li><a href="javascript:void(0)" id="pro_st_tb_7" class="<%= show_memu == 'trainig_task' ? 'active' : ''%>" onclick="project_setting(7);">实训任务</a></li>
<% end %>
<!--<li id="pro_st_tb_7" class="pro_st_normaltab" onclick="project_setting(7);">活动(时间跟踪)</li>-->
<!--<li id="pro_st_tb_8" class="pro_st_normaltab" onclick="project_setting(8);">代码评审</li>-->
</ul>
@ -51,6 +54,10 @@
<div class="<%= show_memu == 'manage_repository' ? 'pro_st_dis' : 'pro_st_undis'%>" id="pro_st_tbc_06">
<%= render :partial=>"projects/settings/new_repositories" if User.current.allowed_to?(:manage_repository, @project)%>
</div><!--tbc_06 end-->
<div class="<%= show_memu == 'training_task' ? 'pro_st_dis' : 'pro_st_undis'%>" id="pro_st_tbc_07">
<%= render :partial=>"projects/settings/new_trainig_task" if User.current.admin? %>
</div><!--tbc_06 end-->
</div>
</div>

View File

@ -0,0 +1,15 @@
<h3>请输入脚本</h3>
<p><%= link_to "开启实训", training_project_execute_project_path(@project) %></p>
<textarea id="pull_request_comment" name="pull_request_comment" class="pullreques_reply_textarea" style="padding-left: 0px;"></textarea>
<textarea>
node()
{
stage "first"
def args = "command=fileExists"
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM', httpMode: 'POST', requestBody: args, url: "http://localhost:8080/jenkins-exec/pipeline/call?taskId=${taskId}"
println('Status: '+response.status)
println('Response: '+response.content)
}
</textarea>

View File

@ -911,6 +911,7 @@ RedmineApp::Application.routes.draw do
post 'unarchive'
post 'close'
post 'reopen'
get 'training_project_execute'
get 'forked_pop'
get 'delete_member_pop', :to => 'projects#delete_member_pop', :via => :get, :as => "delete_member_pop"
get 'search_public_orgs_not_in_project'

View File

@ -0,0 +1,5 @@
class AddScriptToProject < ActiveRecord::Migration
def change
add_column :projects, :script, :text
end
end

View File

@ -0,0 +1,5 @@
class AddPositonToTrainingTask < ActiveRecord::Migration
def change
add_column :training_tasks, :position, :integer, :limit => 1
end
end

File diff suppressed because it is too large Load Diff