diff --git a/jenkins-exec/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch b/jenkins-exec/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch new file mode 100644 index 0000000..6ef634c --- /dev/null +++ b/jenkins-exec/.externalToolBuilders/org.eclipse.wst.validation.validationbuilder.launch @@ -0,0 +1,7 @@ + + + + + + + diff --git a/jenkins-exec/src/main/java/com/educoder/jenkins/controller/GameController.java b/jenkins-exec/src/main/java/com/educoder/jenkins/controller/GameController.java index 2bf63cd..f1d5329 100644 --- a/jenkins-exec/src/main/java/com/educoder/jenkins/controller/GameController.java +++ b/jenkins-exec/src/main/java/com/educoder/jenkins/controller/GameController.java @@ -134,11 +134,10 @@ public class GameController extends BaseController { pipeline = generatePipeline.generateChallengePipeline(params); - + response.put("code", 0); response.put("msg", Base64Helper.encode(pipeline)); - // logger.debug("/game/generatePipelineScriptForChallenge challengeInfo: - // " + challengeInfo); + logger.debug(response.toJSONString()); return response; } @@ -184,7 +183,7 @@ public class GameController extends BaseController { params.put("challengePipeline", new String(challengePipeline)); params.put("pipelineTemplateFileName", pipeLineConfig.getPipelineTemplateFileName().get(index)); params.put("podTemplate",pipeLineConfig.getPodTemplate().get(index)); - + params.put("mainContainer",pipeLineConfig.getMainContainer().get(index)); // 根据运行环境分别得到对应的编译和执行命令 GeneratePipeline generatePipeline = (GeneratePipeline) Class .forName(pipeLineConfig.getClassName().get(index)).newInstance(); @@ -195,7 +194,7 @@ public class GameController extends BaseController { response.put("code", 0); response.put("msg", Base64Helper.encode(pipeline)); -// logger.debug("*****/game/generatePipelineScriptForGame gameInfo: " + gameInfo); + logger.debug(response.toJSONString()); return response; } @@ -215,7 +214,7 @@ public class GameController extends BaseController { // instanceGitURL为学生fork的版本库的地址 jenkinsController.buildJobForInstance(jobNameForInstance, instanceGitURL, 0 + "", 0 + "", 0 + ""); - logger.debug("*****/game/openGameInstance jobNameForInstance: " + jobNameForInstance); + logger.debug(response.toJSONString()); return response; } @@ -292,35 +291,33 @@ public class GameController extends BaseController { * @return: 0 删除成功 * -1 删除失败 * */ - @ApiOperation(value = "删除Job及工作目录下的文件", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) - @RequestMapping(path = "/deleteJob") - public JSONObject deleteJob( - @ApiParam(name = "delJob", required = true, value = "要删除的job的名字") @RequestParam String delJob) - throws Exception { + @ApiOperation(value = "删除Job及工作目录下的文件", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE) + @RequestMapping(path = "/deleteJob") + public JSONObject deleteJob(@ApiParam(name = "jobName", required = true, value = "要删除的job的名字") @RequestParam String jobName) throws Exception { + logger.debug("jobName: " + jobName); + String job = Base64Helper.decode(jobName); + JSONObject response = new JSONObject(); + response.put("code",-1); + //调用Jenkins API删除job + int result= jenkinsApi.deleteJob(job); - JSONObject info = JSONObject.parseObject(delJob); - String job = info.getString("jobName"); + /* + * -1:删除之前job 存在,删除未成功 + * 1;要删除的job不存在(此时不用删除Jenkins工作目录下的文件) + * 0:删除成功 + * */ + if(-1 == result) + { + response.put("code",-1); + return response; + } - JSONObject response = new JSONObject(); - response.put("status", -1); - // 调用Jenkins API删除job - int result = jenkinsApi.deleteJob(job); - - /* - * -1:删除之前job 存在,删除未成功 - * 1;要删除的job不存在(此时不用删除Jenkins工作目录下的文件) - * 0:删除成功 - * */ - if (-1 == result) { - response.put("status", -1); - return response; - } - - if (1 == result || 0 == result) { - response.put("status", 0); - return response; - } - return response; - } + if(1 == result || 0==result) + { + response.put("code",0); + return response; + } + return response; + } } diff --git a/jenkins-exec/src/main/java/com/educoder/jenkins/model/GeneratePipelineJava.java b/jenkins-exec/src/main/java/com/educoder/jenkins/model/GeneratePipelineJava.java index 1b8697a..4163d70 100644 --- a/jenkins-exec/src/main/java/com/educoder/jenkins/model/GeneratePipelineJava.java +++ b/jenkins-exec/src/main/java/com/educoder/jenkins/model/GeneratePipelineJava.java @@ -55,6 +55,8 @@ public class GeneratePipelineJava extends GeneratePipeline{ //提取执行文件名称 String replacedStr[]=params.get("replaceExecuteCommand").split("#"); + if(replacedStr.length<2){ throw new ArrayIndexOutOfBoundsException("提取执行文件名称的替换有误");} + String executeFileName = params.get("challengeProgramName").replace(replacedStr[0], replacedStr[1]); pipeline = pipeline.replace("COMPILECOMMAND", params.get("complieCommand")); @@ -76,10 +78,10 @@ public class GeneratePipelineJava extends GeneratePipeline{ String podTemplate=params.get("podTemplate"); String pipelineTemplateFileName=params.get("pipelineTemplateFileName"); String challengePipeline=params.get("challengePipeline"); - + String mainContainer=params.get("mainContainer"); String fullPipeline=StringUtil.getCofigureFileContent(pipelineTemplateFileName); - - fullPipeline=podTemplate+fullPipeline.replace("CHALLENGEPIPELINES", challengePipeline); + fullPipeline=fullPipeline.replaceFirst("MAINCONTAINER", mainContainer).replace("CHALLENGEPIPELINES", challengePipeline); + fullPipeline=podTemplate+fullPipeline; return fullPipeline; } diff --git a/jenkins-exec/src/main/resources/applicationContext.xml b/jenkins-exec/src/main/resources/applicationContext.xml index 3b22a1c..2e96aff 100644 --- a/jenkins-exec/src/main/resources/applicationContext.xml +++ b/jenkins-exec/src/main/resources/applicationContext.xml @@ -22,9 +22,9 @@ - java - python - jdbc + Java + Python + JDBC @@ -86,9 +86,9 @@ - .java# - .py#.py - .java# + .java# + .py#.py + .java# diff --git a/jenkins-exec/src/main/resources/fullTemplateJava.pipeline b/jenkins-exec/src/main/resources/fullTemplateJava.pipeline index 04d95e1..b1530c1 100644 --- a/jenkins-exec/src/main/resources/fullTemplateJava.pipeline +++ b/jenkins-exec/src/main/resources/fullTemplateJava.pipeline @@ -1,6 +1,6 @@ { -node(PODLABEL) { - +node('PODLABEL') { + container('MAINCONTAINER') { def currentChallenge = Integer.parseInt(instanceChallenge) // 解决stage 0 401没有权限的问题 if (currentChallenge == 0) { @@ -22,7 +22,7 @@ node(PODLABEL) { git url: instanceGitURL CHALLENGEPIPELINES - +} } } // 传送运行结果到BDWeb diff --git a/jenkins-exec/src/main/resources/podTemplate.properties b/jenkins-exec/src/main/resources/podTemplate.properties index 6c35100..fae0144 100644 --- a/jenkins-exec/src/main/resources/podTemplate.properties +++ b/jenkins-exec/src/main/resources/podTemplate.properties @@ -2,4 +2,4 @@ workspace=/var/lib/jenkins/workspace remoteWorkspace=/home/jenkins java_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'openjdk', image: 'openjdk:latest', ttyEnabled: true)],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')]) python_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'python', image: 'python:latest', ttyEnabled: true)],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')]) -jdbc_podTemplate=null +jdbc_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'openjdk', image: 'openjdk:latest', ttyEnabled: true), containerTemplate(name: 'mysql', image: 'mysql57:latest', ttyEnabled: true, command: '/start.sh')],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')]) diff --git a/jenkins-exec/src/test/java/cn/lili/test/TestString.java b/jenkins-exec/src/test/java/cn/lili/test/TestString.java index dbfe3fe..a61a9d9 100644 --- a/jenkins-exec/src/test/java/cn/lili/test/TestString.java +++ b/jenkins-exec/src/test/java/cn/lili/test/TestString.java @@ -18,7 +18,8 @@ public class TestString { @Test public void testMap(){ Map testmap=new HashMap(); - System.out.println(testmap.get(null)); + testmap.put("1", " "+"1"+" "); + System.out.println(testmap.get("1")); } }