更改swagger扫描包
This commit is contained in:
parent
68e39f39d6
commit
1477675b01
|
@ -32,22 +32,6 @@ public class JenkinsController {
|
|||
@Autowired
|
||||
JenkinsApi jenkinsApi;
|
||||
|
||||
@ApiOperation(value = "开始一个实训", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@ApiResponse(code = 200, message = "success", response = JSONObject.class)
|
||||
@RequestMapping(path="/openGameTraining",method = RequestMethod.POST)
|
||||
public JSONObject openTrainingInstance(String jobNameForInstance, String gamePipelineScript, String InstanceGitURL){
|
||||
JSONObject response = new JSONObject();
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "保存输入输出到文件", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
public JSONObject saveTestCases (String shixunId, String cases){
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "创建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@ApiResponse(code = 200, message = "success", response = JSONObject.class)
|
||||
@RequestMapping(path="/createJobForInstance",method = RequestMethod.POST)
|
||||
|
@ -109,95 +93,5 @@ public class JenkinsController {
|
|||
response.put("msg", "run job success");
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ApiOperation(value = "创建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@ApiResponse(code = 200, message = "success", response = JSONObject.class)
|
||||
@RequestMapping(path="/createJob",method = RequestMethod.POST)
|
||||
public JSONObject createJob(@ApiParam(name = "jobName", required = true, value = "job的名字,不能重复") @RequestParam String jobName,
|
||||
@ApiParam(name = "pipeLine", required = true, value = "pipeLine脚本,用base64编码") @RequestParam String pipeLine,
|
||||
@ApiParam(name = "params", required = true, value = "job的参数,以json字符串的形式") @RequestParam String params){
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
Map jobParams = JSONObject.parseObject(params, Map.class);
|
||||
for (Object s : jobParams.keySet()) {
|
||||
jobParams.put(s, "");
|
||||
}
|
||||
|
||||
logger.debug("调用[createJob]: jobName=" + jobName + " pipeLine=" + pipeLine + JSONObject.toJSONString(jobParams));
|
||||
|
||||
pipeLine = Base64Helper.decode(pipeLine);
|
||||
|
||||
String result = jenkinsApi.createJob(jobName, pipeLine, jobParams);
|
||||
logger.debug(result);
|
||||
}catch (Exception e){
|
||||
logger.error("createJob", e);
|
||||
if (e.getMessage().startsWith("A job already exists")){
|
||||
// 这里后续考虑是不是也替换成status
|
||||
response.put("code", -2);
|
||||
response.put("msg", jobName+"already exists");
|
||||
return response;
|
||||
}
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "create job success.");
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "构建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path="/buildJob")
|
||||
public JSONObject buildJob(@ApiParam(name = "jobName", required = true, value = "job的名字") @RequestParam String jobName,
|
||||
@ApiParam(name = "gitUrl", required = true, value = "学员对应当前实训版本库地址") @RequestParam String gitUrl,
|
||||
@ApiParam(name = "taskId", required = true, value = "本次评测ID") @RequestParam String taskId,
|
||||
@ApiParam(name = "step", required = true, value = "当前处在第几关") @RequestParam String step
|
||||
){
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
logger.debug("调用[buildJob]: jobName=" + jobName + "taskId "+taskId+" step "+step+" gitUrl "+gitUrl);
|
||||
gitUrl = Base64Helper.decode(gitUrl);
|
||||
jenkinsApi.buildJob(jobName, taskId, step, gitUrl);
|
||||
}catch (Exception e){
|
||||
logger.error("buildJob", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "run job success");
|
||||
return response;
|
||||
}
|
||||
|
||||
@ApiOperation(value = "构建一个job", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path="/buildJob")
|
||||
public JSONObject buildJob(@ApiParam(name = "jobName", required = true, value = "job的名字") @RequestParam String jobName,
|
||||
@ApiParam(name = "gitUrl", required = true, value = "学员对应当前实训版本库地址") @RequestParam String gitUrl,
|
||||
@ApiParam(name = "taskId", required = true, value = "本次评测ID") @RequestParam String taskId,
|
||||
@ApiParam(name = "step", required = true, value = "当前处在第几关") @RequestParam String step,
|
||||
@ApiParam(name = "stepParams", required = true, value = "本关构建的参数,以json字符串的形式") @RequestParam String stepParams){
|
||||
JSONObject response = new JSONObject();
|
||||
try {
|
||||
logger.debug("调用[buildJob]: jobName=" + jobName + "taskId "+taskId+" step "+step+" gitUrl "+gitUrl+" stepParams "+ stepParams);
|
||||
gitUrl = Base64Helper.decode(gitUrl);
|
||||
jenkinsApi.buildJob(jobName, taskId, step, gitUrl, stepParams);
|
||||
}catch (Exception e){
|
||||
logger.error("buildJob", e);
|
||||
response.put("code", -1);
|
||||
response.put("msg", e.getMessage());
|
||||
return response;
|
||||
}
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "run job success");
|
||||
return response;
|
||||
}
|
||||
**/
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
|
||||
<!--指明 controller 所在包,并扫描其中的注解-->
|
||||
<context:component-scan base-package="cn.guange.app.jenkins.controller"/>
|
||||
<context:component-scan base-package="com.educoder.jenkins.controller"/>
|
||||
|
||||
<!-- 静态资源(js、image等)的访问 -->
|
||||
<mvc:default-servlet-handler/>
|
||||
|
|
|
@ -34,6 +34,10 @@ public class JenkinsApiTest extends SpringTestBase {
|
|||
|
||||
@Test
|
||||
public void createJob() throws Exception {
|
||||
JenkinsServer server = new JenkinsServer(new URI(appConfig.getJenkinsUrl()), appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
if (server.getJob("test") != null) {
|
||||
server.deleteJob("test");
|
||||
}
|
||||
|
||||
String pipeLine = ReadFileUtil.readPipeline("src/test/resources/pipeline");
|
||||
|
||||
|
@ -49,29 +53,29 @@ public class JenkinsApiTest extends SpringTestBase {
|
|||
|
||||
@Test
|
||||
public void buildJob() throws Exception {
|
||||
jenkinsApi.buildJob("test", "1", "2", "https://bdgit.trustie.net/forge01/linkedlistdemo.git", "{}");
|
||||
jenkinsApi.buildJob("for_build_job", "1", "2", "https://bdgit.trustie.net/forge01/linkedlistdemo.git", "{}");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void getJobXml() throws Exception {
|
||||
String test = jenkinsApi.getJobXml("jenkins_param_test");
|
||||
String test = jenkinsApi.getJobXml("for_build_job");
|
||||
System.out.println(test);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void teardown() {
|
||||
try {
|
||||
JenkinsServer jenkinsServer = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
|
||||
appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
|
||||
for(int i = 0; i < 100; i++)
|
||||
if (jenkinsServer.getJob("test_time" + i) != null) {
|
||||
jenkinsServer.deleteJob("test_time" + i);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
//// @Test
|
||||
// public void teardown() {
|
||||
// try {
|
||||
// JenkinsServer jenkinsServer = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
|
||||
// appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
//
|
||||
// for(int i = 0; i < 100; i++)
|
||||
// if (jenkinsServer.getJob("test_time" + i) != null) {
|
||||
// jenkinsServer.deleteJob("test_time" + i);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
}
|
|
@ -5,6 +5,7 @@ import com.educoder.jenkins.api.JenkinsApi;
|
|||
import com.educoder.jenkins.settings.AppConfig;
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
|
@ -22,6 +23,11 @@ public class JenkinsTest extends SpringTestBase {
|
|||
@Autowired
|
||||
JenkinsApi jenkinsApi;
|
||||
|
||||
@Test
|
||||
public void testConfig(){
|
||||
Assert.assertTrue(appConfig!=null);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void createJob() {
|
||||
// 创建job
|
||||
|
|
Loading…
Reference in New Issue