修改错误日志记录
This commit is contained in:
commit
1416409348
|
@ -0,0 +1,128 @@
|
|||
jobName: myshixun_220 buildID: 1 biuldNum: 14 开始时间:2017-06-12 15:36:04
|
||||
errInfo: stillWaiting 9 运行时间:0
|
||||
运行参数:{instanceChallenge=1, buildID=1, resubmit=1, instanceGitURL=}
|
||||
Started by user root
|
||||
[Pipeline] node
|
||||
Running on master in /var/lib/jenkins/workspace/myshixun_220
|
||||
[Pipeline] {
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
Sleeping for 1 sec
|
||||
[Pipeline] sleep
|
||||
|
||||
|
|
@ -103,6 +103,86 @@
|
|||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-rs-client</artifactId>
|
||||
<version>3.0.0-milestone1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http-hc</artifactId>
|
||||
<!-- 2.7.8 or 3.0.0-milestone1 -->
|
||||
<version>3.1.11</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.fabric8/kubernetes-api -->
|
||||
<dependency>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>kubernetes-api</artifactId>
|
||||
<version>2.2.211</version>
|
||||
</dependency>
|
||||
<!-- 2.2.211https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.12</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.json/json -->
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20160212</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>1.1.0.Final</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.fabric8/fabric8-utils -->
|
||||
<dependency>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>fabric8-utils</artifactId>
|
||||
<version>2.2.211</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.fabric8/openshift-client -->
|
||||
<dependency>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>openshift-client</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/io.fabric8/openshift-client -->
|
||||
<dependency>
|
||||
<groupId>io.fabric8</groupId>
|
||||
<artifactId>openshift-client</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/dnsjava/dnsjava -->
|
||||
<dependency>
|
||||
<groupId>dnsjava</groupId>
|
||||
<artifactId>dnsjava</artifactId>
|
||||
<version>2.1.8</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.7.4</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.fusesource.jansi/jansi -->
|
||||
<dependency>
|
||||
<groupId>org.fusesource.jansi</groupId>
|
||||
<artifactId>jansi</artifactId>
|
||||
<version>1.11</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -45,6 +45,7 @@ public class JenkinsApi {
|
|||
//连接到Jenkins
|
||||
jenkins = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
|
||||
appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
|
||||
} catch (Exception e) {
|
||||
logger.error("连接jenkins出错", e);
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -15,7 +15,8 @@ import org.springframework.stereotype.Service;
|
|||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Iterator;
|
||||
/**
|
||||
* Created by guange on 17/02/2017.
|
||||
*/
|
||||
|
@ -39,7 +40,7 @@ public class TrustieApi {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpHelper.sendPost(appConfig.getTrustieUrl(),
|
||||
result);
|
||||
HttpHelper.sendPost(appConfig.getTrustieUrl(),result);
|
||||
logger.debug("信息已回传给前端");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
package com.educoder.jenkins.controller;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
|
||||
import com.educoder.jenkins.settings.AppConfig;
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||
import com.offbytwo.jenkins.model.Job;
|
||||
import org.springframework.stereotype.Component;;
|
||||
/**
|
||||
* @author lqk
|
||||
* @version 0.1
|
||||
* @see
|
||||
*<p>为每次构建创建一个线程,用以放入线程池实现对构建任务的管理</p>
|
||||
*/
|
||||
@Component("BuildThread")
|
||||
@Scope("prototype")
|
||||
public class BuildThread implements Runnable{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BuildThread.class);
|
||||
|
||||
@Autowired
|
||||
AppConfig appConfig;
|
||||
|
||||
private JenkinsServer jenkins = null;
|
||||
|
||||
//存放要构建的job的名称
|
||||
private String jobName;
|
||||
//存放需要构建的job的参数
|
||||
private Map<String, String> params = new HashMap<String,String>();
|
||||
|
||||
//初始化,连接到服务器
|
||||
public void init()
|
||||
{
|
||||
logger.debug("执行初始化获取JenkinsUrl:" + appConfig.getJenkinsUrl());
|
||||
try
|
||||
{
|
||||
//连接到Jenkins
|
||||
logger.debug("appconfig:" + appConfig.getJenkinsUrl());
|
||||
jenkins = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
|
||||
appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
logger.debug("已为job:" + this.jobName + "的构建连接到Jenkins服务器");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("连接jenkins出错");
|
||||
}
|
||||
}
|
||||
|
||||
//设置构建job时需要的job名称及构建参数
|
||||
public void setBuildInfo(String jobName,Map<String,String> params)
|
||||
{
|
||||
this.jobName = jobName;
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
private void buildJob() throws IOException
|
||||
{
|
||||
init();
|
||||
logger.debug("发起构建请求:jobName:" + this.jobName);
|
||||
JobWithDetails job = jenkins.getJob(this.jobName);
|
||||
try {
|
||||
job.build(this.params);
|
||||
}catch (Exception e)
|
||||
{
|
||||
logger.error("构建job:" + this.jobName + "失败");
|
||||
}
|
||||
logger.debug("jobName:" + this.jobName+"构建请求已发送");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("job:" + this.jobName + "线程开始执行");
|
||||
|
||||
long startBuild= System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
buildJob();
|
||||
} catch (IOException e) {
|
||||
logger.error("job:" + jobName + "请求构建失败");
|
||||
System.exit(-1);
|
||||
}
|
||||
Map<String, Job> jobs = null;
|
||||
try {
|
||||
jobs = jenkins.getJobs();
|
||||
}catch (IOException e){
|
||||
logger.error("获取job时失败");
|
||||
}
|
||||
logger.info("轮训获取状态");
|
||||
while(true) {
|
||||
try {
|
||||
|
||||
JobWithDetails job = jobs.get(jobName).details();
|
||||
try {
|
||||
BuildWithDetails buildWithDetails = job.getLastBuild().details();
|
||||
//正在构建
|
||||
if(buildWithDetails.isBuilding()) {
|
||||
long afterBuild = System.currentTimeMillis();
|
||||
if(afterBuild-startBuild > 1000*60)
|
||||
{
|
||||
logger.debug("job构建超时,退出");
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}else{
|
||||
//构建完成
|
||||
logger.debug("构建完成");
|
||||
break;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("查询构建状态时出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("获取构建状态失败准别退出执行下一次构建");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("job:" + this.jobName + "线程退出");
|
||||
}
|
||||
|
||||
private int delJob()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.educoder.jenkins.controller;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.educoder.jenkins.api.JenkinsApi;
|
||||
import com.educoder.jenkins.service.BuildThread;
|
||||
import com.educoder.jenkins.settings.AppConfig;
|
||||
import com.educoder.jenkins.utils.Base64Helper;
|
||||
import io.swagger.annotations.Api;
|
||||
|
@ -12,6 +13,8 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@ -33,14 +36,12 @@ public class JenkinsController extends BaseController {
|
|||
JenkinsApi jenkinsApi;
|
||||
@Autowired
|
||||
AppConfig appConfig;
|
||||
//String poolsize = appConfig.getPoolSize();
|
||||
//public int poolSize=Integer.parseInt(appConfig.getPoolSize());
|
||||
//创建进程池
|
||||
// int poolSize=Integer.parseInt(appConfig.getPoolSize());
|
||||
// private ExecutorService pool = Executors.newFixedThreadPool(poolSize);
|
||||
private static ExecutorService pool = Executors.newFixedThreadPool(6);
|
||||
|
||||
|
||||
//public ExecutorService pool = Executors.newFixedThreadPool(1);
|
||||
public static ExecutorService pool = null;
|
||||
private static final Logger logger = LoggerFactory.getLogger(JenkinsController.class);
|
||||
|
||||
/**
|
||||
* 0:job存在并成功删除
|
||||
* -1;job存在未成功删除
|
||||
|
@ -79,8 +80,8 @@ public class JenkinsController extends BaseController {
|
|||
throws Exception {
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
long threadCount = ((ThreadPoolExecutor)pool).getTaskCount();
|
||||
BlockingQueue bq = ((ThreadPoolExecutor)pool).getQueue();
|
||||
/* long threadCount = ((ThreadPoolExecutor)pool).getTaskCount();
|
||||
BlockingQueue bq = ((ThreadPoolExecutor)pool).getQueue();*/
|
||||
|
||||
Map jobParamsMap = new HashMap();
|
||||
jobParamsMap.put("instanceGitURL", "");
|
||||
|
@ -115,30 +116,30 @@ public class JenkinsController extends BaseController {
|
|||
|
||||
|
||||
logger.debug(jobNameForInstance+"\t"+instanceGitURL+"\t"+buildID+"\t"+instanceChallenge+"\t"+resubmit);
|
||||
|
||||
if(pool == null)
|
||||
pool = Executors.newFixedThreadPool(Integer.parseInt(appConfig.getPoolSize()));
|
||||
JSONObject response = new JSONObject();
|
||||
|
||||
instanceGitURL = Base64Helper.decode(instanceGitURL);
|
||||
|
||||
/* //获取阻塞队列,用以计算队列中还有多少任务在等待
|
||||
BlockingQueue bq = ((ThreadPoolExecutor)pool).getQueue();
|
||||
int waitNum = bq.size();*/
|
||||
|
||||
//为新来的job生成一个线程
|
||||
BuildThread buildThread = (BuildThread)AppContext.appContext.getBean("BuildThread");
|
||||
Map buildParams = new HashMap();
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
|
||||
BuildThread buildThreadNew = (BuildThread)ctx.getBean("BuildThreadNew");
|
||||
//BuildThread buildThreadNew = (BuildThread)AppContext.appContext.getBean("BuildThread");
|
||||
Map<String,String> buildParams = new HashMap<String,String>();
|
||||
buildParams.put("buildID", buildID);
|
||||
buildParams.put("instanceChallenge", instanceChallenge);
|
||||
buildParams.put("instanceGitURL", instanceGitURL);
|
||||
buildParams.put("resubmit", resubmit);
|
||||
buildThread.setBuildInfo(jobNameForInstance,buildParams);
|
||||
pool.execute(buildThread);
|
||||
|
||||
/*
|
||||
* 先获取阻塞队列,然后获取阻塞队列的大小即可得前方还有多少job在等待构建
|
||||
* 这个等以后有这方面的需求再添加
|
||||
BlockingQueue bq = ((ThreadPoolExecutor)pool).getQueue();
|
||||
int waitNum = bq.size();
|
||||
*/
|
||||
//给Jenkins发起请求开始构建
|
||||
//jenkinsApi.buildJobWithFlag(jobNameForInstance, buildID, instanceChallenge, instanceGitURL, resubmit);
|
||||
buildThreadNew.setBuildInfo(jobNameForInstance,buildParams,buildID,resubmit);
|
||||
pool.execute(buildThreadNew);
|
||||
|
||||
response.put("code", 0);
|
||||
//response.put("waitNum",waitNum);
|
||||
response.put("msg", "run job success");
|
||||
|
||||
logger.debug("*****/api/buildJobForInstance jobNameForInstance:" + jobNameForInstance);
|
||||
|
|
|
@ -72,7 +72,6 @@ public class PipeLineController extends BaseController {
|
|||
StringBuffer errorInfo = new StringBuffer();
|
||||
if ("-1".equals(testInfo.getStatus()) && "Y29tcGlsZSBzdWNjZXNzZnVsbHk=".equals(compileResult)) {
|
||||
errorInfo.append("测试结果不匹配:");
|
||||
|
||||
for (int i = 0; i < testInfo.getMsg().size(); i++) {
|
||||
if ("0".equals(testInfo.getMsg().get(i).getPassed())) {
|
||||
errorInfo.append("测试集" + testInfo.getMsg().get(i).getCaseId() + ":");
|
||||
|
@ -94,60 +93,4 @@ public class PipeLineController extends BaseController {
|
|||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/*@ApiOperation(value = "将错误结果回传到BDWeb", httpMethod = "POST", produces = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
|
||||
@RequestMapping(path = "/postErrToBDWeb")
|
||||
public JSONObject postErrToBDWeb(String buildID, String errType,String errInfo) throws Exception {
|
||||
|
||||
logger.debug("*****//*pipeline/postErrToBDWeb buildID: " + buildID + ",errType= " + errType + ",errInfo= " + errInfo );
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
|
||||
*//* List<String> inputs = JSON.parseArray(in, String.class);
|
||||
List<String> outputs = JSON.parseArray(out, String.class);*//*
|
||||
|
||||
TestInfo testInfo = new TestInfo(buildID, "0", compileResult, reSubmit);
|
||||
|
||||
for (int i = 0; i < expectedOuts.size(); i++) {
|
||||
String pass = "1";
|
||||
String str_out = new String(Base64Helper.decode(outputs.get(i)).getBytes(), "UTF-8");
|
||||
str_out = str_out.replace("\r\n", "\n").trim();
|
||||
String str_exceptOut = new String(Base64Helper.decode(expectedOuts.get(i)).getBytes(), "UTF-8");
|
||||
str_exceptOut = str_exceptOut.replace("\r\n", "\n").trim();
|
||||
if (!str_out.equals(str_exceptOut)) {
|
||||
pass = "0";
|
||||
testInfo.setStatus("-1");
|
||||
}
|
||||
Case caseOne = new Case((i + 1) + "", inputs.get(i), outputs.get(i), expectedOuts.get(i), isPublics.get(i),
|
||||
pass);
|
||||
testInfo.getMsg().add(caseOne);
|
||||
}
|
||||
|
||||
// 假如运行结果错误
|
||||
StringBuffer errorInfo = new StringBuffer();
|
||||
if ("-1".equals(testInfo.getStatus()) && "Y29tcGlsZSBzdWNjZXNzZnVsbHk=".equals(compileResult)) {
|
||||
errorInfo.append("测试结果不匹配:");
|
||||
|
||||
for (int i = 0; i < testInfo.getMsg().size(); i++) {
|
||||
if ("0".equals(testInfo.getMsg().get(i).getPassed())) {
|
||||
errorInfo.append("测试集" + testInfo.getMsg().get(i).getCaseId() + ":");
|
||||
errorInfo.append("输出与期待输出不匹配; ");
|
||||
}
|
||||
}
|
||||
testInfo.setOutPut(Base64Helper.encode(errorInfo.toString()));
|
||||
}
|
||||
|
||||
String jsonTestInfo = JSON.toJSONString(testInfo);
|
||||
Map map = new HashMap();
|
||||
map.put("jsonTestDetails", jsonTestInfo);
|
||||
trustieApi.commitResultToTrustie(map);
|
||||
|
||||
response.put("code", 0);
|
||||
response.put("msg", "结果回传成功");
|
||||
|
||||
return response;
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -14,7 +14,10 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.educoder.jenkins.controller.GameController;
|
||||
import com.educoder.jenkins.utils.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -27,17 +30,7 @@ import com.educoder.jenkins.utils.StringUtil;
|
|||
*/
|
||||
|
||||
public class GeneratePipelineJava extends GeneratePipeline{
|
||||
|
||||
/**
|
||||
* <一句话功能简述>
|
||||
* <功能详细描述>
|
||||
* @param CHALLENGESTAGE
|
||||
* @param TRAININGID
|
||||
* @param compileCommand
|
||||
* @param executeCommand
|
||||
* @param templateFileName
|
||||
* @see [类、类#方法、类#成员]
|
||||
*/
|
||||
private final static Logger logger = LoggerFactory.getLogger(GameController.class);
|
||||
public GeneratePipelineJava() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
|
@ -58,9 +51,10 @@ public class GeneratePipelineJava extends GeneratePipeline{
|
|||
if(replacedStr.length<2 || replacedStr.length%2!=0){ throw new ArrayIndexOutOfBoundsException("提取执行文件名称的替换有误");}
|
||||
String executeFileName = params.get("challengeProgramName");
|
||||
for(int i=0;i<replacedStr.length;i=i+2)
|
||||
{
|
||||
{
|
||||
executeFileName = executeFileName.replace(replacedStr[i], replacedStr[i+1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pipeline = pipeline.replace("COMPILECOMMAND", params.get("complieCommand"));
|
||||
pipeline = pipeline.replace("EXECUTECOMMAND", params.get("executeCommand"));
|
||||
|
|
|
@ -0,0 +1,261 @@
|
|||
package com.educoder.jenkins.service;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.regex.*;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.educoder.jenkins.api.TrustieApi;
|
||||
import com.educoder.jenkins.model.Case;
|
||||
import com.educoder.jenkins.model.TestInfo;
|
||||
import com.educoder.jenkins.settings.AppConfig;
|
||||
import com.educoder.jenkins.utils.Base64Helper;
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.http.StreamingHttpOutputMessage;
|
||||
import java.text.SimpleDateFormat;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||
import com.offbytwo.jenkins.model.Job;
|
||||
import com.educoder.jenkins.service.JobUtils;
|
||||
import com.educoder.jenkins.service.JobMonitor;
|
||||
import com.educoder.jenkins.settings.PipeLineConfig;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;;
|
||||
/**
|
||||
* @author lqk
|
||||
* @version 0.1
|
||||
* @see
|
||||
*<p>为每次构建创建一个线程,用以放入线程池实现对构建任务的管理</p>
|
||||
*/
|
||||
@Service("BuildThreadNew")
|
||||
@Scope("prototype")
|
||||
public class BuildThread implements Runnable{
|
||||
private static final Logger logger = LoggerFactory.getLogger(BuildThread.class);
|
||||
|
||||
@Autowired
|
||||
AppConfig appConfig;
|
||||
@Autowired
|
||||
PipeLineConfig pipeLineConfig;
|
||||
@Autowired
|
||||
TrustieApi trustieApi;
|
||||
JobUtils jobTools = new JobUtils();
|
||||
private JenkinsServer jenkins = null;
|
||||
JobMonitor monitor = new JobMonitor();
|
||||
//存放要构建的job的名称
|
||||
private String jobName;
|
||||
private String buildID;
|
||||
private String resubmit;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
//存放需要构建的job的参数
|
||||
private Map<String, String> params = new HashMap<String,String>();
|
||||
|
||||
//初始化,连接到服务器
|
||||
public void init()
|
||||
{
|
||||
logger.debug("执行初始化获取JenkinsUrl:" + appConfig.getJenkinsUrl());
|
||||
try
|
||||
{
|
||||
//连接到Jenkins
|
||||
jenkins = new JenkinsServer(new URI(appConfig.getJenkinsUrl()),
|
||||
appConfig.getJenkisUserName(), appConfig.getJenkisPassWord());
|
||||
logger.debug("已为job:" + this.jobName + "的构建连接到Jenkins服务器");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.error("连接jenkins出错");
|
||||
}
|
||||
}
|
||||
|
||||
//设置构建job时需要的job名称及构建参数
|
||||
public void setBuildInfo(String jobName,Map<String,String> params,String buildID,String resubmit)
|
||||
{
|
||||
this.jobName = jobName;
|
||||
this.params = params;
|
||||
this.buildID = buildID;
|
||||
this.resubmit = resubmit;
|
||||
}
|
||||
|
||||
private void buildJob() throws IOException
|
||||
{
|
||||
logger.debug("发起构建请求:jobName:" + this.jobName);
|
||||
JobWithDetails job = jenkins.getJob(this.jobName);
|
||||
try {
|
||||
job.build(this.params);
|
||||
}catch (Exception e)
|
||||
{
|
||||
logger.error("构建job:" + this.jobName + "失败");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("jobName:" + this.jobName+"构建请求已发送");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
logger.info("job:" + this.jobName + "线程开始执行");
|
||||
|
||||
//初始化Jenkins连接
|
||||
init();
|
||||
|
||||
//判断请求构建的job是否存在
|
||||
boolean jobExist = true;
|
||||
try {
|
||||
JobWithDetails existJob = jenkins.getJob(this.jobName);
|
||||
if(existJob == null)
|
||||
//job不存在时置jobExist为FALSE
|
||||
jobExist = false;
|
||||
}catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
//job不存在时,向前端发送job不存在的错误信息
|
||||
if(!jobExist)
|
||||
{
|
||||
logger.debug("job:" + this.jobName + "不存在,线程退出");
|
||||
try {
|
||||
//job不存在时错误码为9
|
||||
postErrToTrustie("jobNoExist", 1, buildID,resubmit,jobName);
|
||||
return;
|
||||
} catch (Exception e)
|
||||
{
|
||||
logger.error("jobName不存在," + this.jobName + "向前端发送错误信息失败");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//获取请求构建的开始时间
|
||||
long startBuild= System.currentTimeMillis();
|
||||
//job存在则发起构建请求
|
||||
try {
|
||||
buildJob();
|
||||
} catch (IOException e) {
|
||||
logger.error("job:" + jobName + "请求构建失败");
|
||||
return;
|
||||
}
|
||||
Map<String, Job> jobs = null;
|
||||
try {
|
||||
jobs = jenkins.getJobs();
|
||||
}catch (IOException e){
|
||||
logger.error("获取job时失败");
|
||||
}
|
||||
logger.info("轮训获取状态");
|
||||
while(true) {
|
||||
try {
|
||||
/* JobWithDetails job = jenkins.getJob(jobName).details();*/
|
||||
JobWithDetails job = jobs.get(jobName).details();
|
||||
try {
|
||||
BuildWithDetails buildWithDetails = job.getLastBuild().details();
|
||||
String jobInfo = "jobName: " + jobName + '\t' + "buildID: " + buildID + '\t' + "biuldNum: " + buildWithDetails.getNumber()
|
||||
+ '\t' + "开始时间:" + simpleDateFormat.format(new Date(buildWithDetails.getTimestamp())) + '\n';
|
||||
//正在构建
|
||||
if(buildWithDetails.isBuilding())
|
||||
{
|
||||
long afterBuild = System.currentTimeMillis();
|
||||
if(afterBuild-startBuild > 1000*60)
|
||||
{
|
||||
logger.debug("job构建超时,退出");
|
||||
//构建超时则获取控制台输出以判断job出错情况
|
||||
String consoleOut = buildWithDetails.getConsoleOutputText();
|
||||
buildWithDetails.Stop();
|
||||
int errCode = monitor.getErrCode(consoleOut);
|
||||
if(errCode == 0)
|
||||
break;
|
||||
//当job构建结束(以失败状态结束)时返回的错误码大于-4小于0
|
||||
if(errCode < 4) {
|
||||
postErrToTrustie("buildFailed", errCode, buildID, jobName,resubmit);
|
||||
jobInfo = jobInfo + "errInfo: " + "buildFailed " + errCode + '\t' +"运行时间:" + buildWithDetails.getDuration() + "\n" + "运行参数:"
|
||||
+ params + '\n' + consoleOut + '\n';
|
||||
logger.error(jobInfo);
|
||||
|
||||
}
|
||||
if (errCode > 4 || errCode == 4) {
|
||||
postErrToTrustie("stillWaiting", errCode, buildID, jobName,resubmit);
|
||||
jobInfo = jobInfo +"errInfo: " + "stillWaiting " + errCode + '\t' + "运行时间:" + buildWithDetails.getDuration() + "\t\n" + "运行参数:"
|
||||
+ params + '\n' + consoleOut + '\n';
|
||||
logger.error(jobInfo);
|
||||
}
|
||||
break;
|
||||
}
|
||||
//每隔一秒查询一次,避免负载过重
|
||||
Thread.sleep(1000*1);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.debug("构建结束");
|
||||
//构建超时则获取控制台输出以判断job出错情况
|
||||
String consoleOut = buildWithDetails.getConsoleOutputText();
|
||||
int errCode = monitor.getErrCode(consoleOut);
|
||||
if(errCode == 0) {
|
||||
logger.debug("job:" + this.jobName + "成功构建");
|
||||
break;
|
||||
}
|
||||
//当job构建结束(以失败状态结束)时返回的错误码大于-4小于0
|
||||
if(errCode < 6) {
|
||||
logger.debug("job构建结束但是失败;errCode:" + errCode);
|
||||
postErrToTrustie("buildFailed", errCode,buildID,jobName,resubmit);
|
||||
jobInfo = jobInfo + "errInfo: " + "buildFailed " + errCode + '\n' + "运行时间:" + buildWithDetails.getDuration() + '\n' + "运行参数:"
|
||||
+ params + '\n' + consoleOut + '\n';
|
||||
logger.error(jobInfo);
|
||||
}
|
||||
if (errCode > 6 || errCode == 6) {
|
||||
postErrToTrustie("stillWaiting", errCode, buildID, jobName, resubmit);
|
||||
jobInfo = jobInfo + "errInfo: " + "stillwaiting " + errCode + '\n' + "运行时间:" + (System.currentTimeMillis()-startBuild)/1000 + '\n' + "运行参数:"
|
||||
+ params + '\n' + consoleOut + '\n';
|
||||
logger.error(jobInfo);
|
||||
}
|
||||
logger.debug("*******************************线程退出*********************");
|
||||
break;
|
||||
}
|
||||
}catch (Exception e) {
|
||||
logger.error("查询构建状态时出错");
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("获取构建状态失败准别退出执行下一次构建");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.debug("job:" + this.jobName + "线程退出");
|
||||
}
|
||||
|
||||
/**
|
||||
* 当job构建失败导致前台收不到错误信息时,就由中间层发送报错信息给前台
|
||||
* 为了使前端能够解析错误信息,信息传输格式与job构建成功传输至前端的JSON一致。
|
||||
*/
|
||||
public void postErrToTrustie(String buildFailed, int errCode, String buildID, String jobName, String reSubmit)throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
logger.debug("********postErrToTrustie:errCode:" + errCode + "********");
|
||||
|
||||
TestInfo testInfo = new TestInfo(buildID, "-1", Base64Helper.encode(buildFailed), reSubmit);
|
||||
Case caseOne = new Case(0 + "", " ", " ", " ", 1+"", 0+"");
|
||||
testInfo.getMsg().add(caseOne);
|
||||
StringBuffer errorInfo = new StringBuffer("error while building: " + buildFailed + ";errCode:88-" + errCode);
|
||||
testInfo.setOutPut(Base64Helper.encode(errorInfo.toString()));
|
||||
String errInfo = JSON.toJSONString(testInfo);
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("jsonTestDetails",errInfo);
|
||||
logger.debug("errInfo:" + map);
|
||||
try {
|
||||
trustieApi.commitResultToTrustie(map);
|
||||
}catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
logger.debug("传送错误信息至前端时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug("报错信息已回传给trustie; errCode:88-" + errCode);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,143 @@
|
|||
package com.educoder.jenkins.service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.educoder.jenkins.api.TrustieApi;
|
||||
import com.educoder.jenkins.utils.Base64Helper;
|
||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.educoder.jenkins.service.JobUtils;
|
||||
import com.educoder.jenkins.model.Case;
|
||||
import com.educoder.jenkins.model.TestInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
@Service("JobMonitor")
|
||||
public class JobMonitor {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JobMonitor.class);
|
||||
/**
|
||||
* job构建超时的时候主动向Jenkins发送请求,通过获取job的控制台上输出
|
||||
* 来分析job的运行情况。对应于不同的错误情况返回不同的错误码
|
||||
* @param consoleOut
|
||||
* @return
|
||||
*/
|
||||
public int getErrCode(String consoleOut) {
|
||||
JobUtils tools = new JobUtils();
|
||||
/**
|
||||
* job构建成功且将信息回传给了trustie
|
||||
* ****结果回传成功*****Finished:SUCCESS
|
||||
*/
|
||||
String regexSUCCESS = "([\\s\\S]*)结果回传成功([\\s\\S]*)Finished:([\\s\\S]*) SUCCESS([\\s\\S]*)";
|
||||
String regexStage0 = "([\\s\\S]*)Finished:([\\s\\S]*) SUCCESS([\\s\\S]*)";
|
||||
/**
|
||||
* 当job构建卡在创建pod这一步的时候会提示:Running on kubernetes-ba8826b6549541c8a861e2df3436356d-410f07d4a3235
|
||||
* in /home/jenkins/workspace/myshixun_672
|
||||
*/
|
||||
String runingOnK8S = "([\\s\\S]*)Running on kubernetes-([\\s\\S]*)";
|
||||
/**
|
||||
* job构建完成但是构建失败
|
||||
* Finished: FAILURE
|
||||
*
|
||||
*/
|
||||
String regexFailure = "([\\s\\S]*)Finished:([\\s\\S]*) FAILURE([\\s\\S]*)";
|
||||
|
||||
/**
|
||||
* startup fail
|
||||
* 系统启动时即失败
|
||||
*/
|
||||
String regexStartFailure = "([\\s\\S]*)startup fail([\\s\\S]*)";
|
||||
/**
|
||||
* pod分配成功但是容器启动失败
|
||||
* Waiting for container container [mysql] of pod [kubernetes-8bb62d2bce0d4b1b840b3f491b5fc856-4e5a8ae4d92b6] to become ready.
|
||||
*/
|
||||
String regexContainerFailure = "(Waiting for container([\\s\\S]*)of pod ([\\s\\S]*) to become ready) |(Waiting for container([\\s\\S]*)to become ready([\\s\\S]*))";
|
||||
|
||||
/**
|
||||
* 不能创建文件夹(挂载失败)
|
||||
*java.io.IOException: Failed to mkdirs/mkdir: cannot create directory ‘test’: File exists
|
||||
*/
|
||||
String regexMakedirs = "java.io.IOException: Failed to mkdirs";
|
||||
String regexMakedirs2 = "([\\s\\S]*)cannot create directory([\\s\\S]*)";
|
||||
/**
|
||||
* pods启动失败或者pod分配失败的报错信息:
|
||||
* Still waiting to schedule task
|
||||
*All nodes of label ‘ubuntuk8s’ are offline
|
||||
* offline)|(Still waiting to schedule task([\s\S]*))
|
||||
*/
|
||||
String regexWaitingPods = "Still waiting to schedule task([\\s\\S]*)";
|
||||
|
||||
/**
|
||||
* 拉取远程代码失败
|
||||
* ERROR: Error cloning remote repo 'origin([\\s\\S]*)''
|
||||
*/
|
||||
String regexGitErr = "([\\s\\S]*)ERROR: Error cloning remote repo([\\s\\S]*)";
|
||||
/**
|
||||
* 语法错误
|
||||
* groovy.lang.MissingPropertyException: No such property: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> for class: WorkflowScript
|
||||
*/
|
||||
String regexSyntaxErr = "groovy.lang.([\\s\\S]*)Exception: No such property:([\\s\\S]*)for class: WorkflowScript";
|
||||
|
||||
/**
|
||||
* 拉取代码成功
|
||||
* git checkout -b master
|
||||
*/
|
||||
String regexGitDone = "([\\s\\S]*)git checkout -b master([\\s\\S]*)";
|
||||
|
||||
/**
|
||||
* 其他不确定的语法或者系统错误,常常是以***Exception:***的形式出现
|
||||
*/
|
||||
String regexSyntaxUnknown = "([\\s\\S]*)Exception([\\s\\S]*)";
|
||||
|
||||
boolean finishDone = tools.findByRegex(regexSUCCESS, consoleOut);
|
||||
boolean stage0Done = tools.findByRegex(regexStage0,consoleOut);
|
||||
boolean startupFailed = tools.findByRegex(regexStartFailure,consoleOut);
|
||||
boolean finishErr = tools.findByRegex(regexFailure, consoleOut);
|
||||
boolean podErr = tools.findByRegex(regexWaitingPods, consoleOut);
|
||||
boolean containerErr = tools.findByRegex(regexContainerFailure, consoleOut);
|
||||
boolean syntaxErr = tools.findByRegex(regexSyntaxErr, consoleOut);
|
||||
boolean gitDone = tools.findByRegex(regexGitDone, consoleOut);
|
||||
boolean mountErr =tools.findByRegex(regexMakedirs, consoleOut);
|
||||
boolean mountErr2 = tools.findByRegex(regexMakedirs2,consoleOut);
|
||||
boolean gitErr = tools.findByRegex(regexGitErr, consoleOut);
|
||||
boolean unknownSyntaxErr = tools.findByRegex(regexSyntaxUnknown, consoleOut);
|
||||
boolean podReady = tools.findByRegex(runingOnK8S,consoleOut);
|
||||
|
||||
if(finishDone || stage0Done)
|
||||
return 0;//构建成功且消息回传成功则返回0
|
||||
/**
|
||||
* 当出现Finished: FAILURE时,说明已经构建完成但由于出现错误未能成功将信息传回trustie。
|
||||
*/
|
||||
if((finishErr && mountErr) || (finishErr && mountErr2) )
|
||||
return 2;//存储失败
|
||||
if((finishErr && syntaxErr) || (finishErr && unknownSyntaxErr))
|
||||
return 3;//语法错误(已知的和未知的)
|
||||
if(finishErr && gitErr)
|
||||
return 4;//git拉取失败
|
||||
if(finishErr)
|
||||
return 5;
|
||||
if(!finishErr && containerErr)
|
||||
return 6;//pod创建成功但容器启动失败
|
||||
if(!finishErr && podErr)
|
||||
return 7;//pod启动或者分配失败
|
||||
if(!finishErr && podReady)
|
||||
return 8;//pod启动或者分配失败
|
||||
/**
|
||||
* 当程序不满足以上条件从而没有返回任何值时,如果job还没有结束构建,
|
||||
* 则可能是由于其他原因导致job一直在循环或者其他原因导致的job一会在等待
|
||||
* -7代表其他原因导致的job一直在构建
|
||||
*/
|
||||
if(!finishErr)
|
||||
return 9;
|
||||
if (startupFailed)
|
||||
return 10;//启动失败
|
||||
return 11;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.educoder.jenkins.service;
|
||||
/**
|
||||
* @author lqk
|
||||
* <p>job构建监控的工具类,提供各种工具性函数</p>
|
||||
*/
|
||||
import java.util.regex.*;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.RandomAccessFile;
|
||||
public class JobUtils {
|
||||
|
||||
/**
|
||||
* 判断给定的字符串是否包含由正则表达式表达的字符串
|
||||
* @param regex 正则表达式
|
||||
* @param src 字符串
|
||||
* @return true:包含
|
||||
* false:不包含
|
||||
*/
|
||||
public boolean findByRegex(String regex,String src)
|
||||
{
|
||||
return Pattern.compile(regex,Pattern.CASE_INSENSITIVE).matcher(src).find();
|
||||
}
|
||||
|
||||
public static void writeErr(String file, String conent)
|
||||
{
|
||||
BufferedWriter out = null;
|
||||
try
|
||||
{
|
||||
out = new BufferedWriter(new OutputStreamWriter(
|
||||
new FileOutputStream(file, true)));
|
||||
out.write(conent+"\r\n");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,12 +30,18 @@ public class AppConfig {
|
|||
|
||||
@Value("${jenkinsConfigXmlPath}")
|
||||
private String jenkinsConfigXmlPath;
|
||||
|
||||
|
||||
@Value("${errConsolePath}")
|
||||
private String errConsolePath;
|
||||
public String getJenkinsConfigXmlPath() {
|
||||
return jenkinsConfigXmlPath;
|
||||
}
|
||||
|
||||
public void setErrConsolePath(String errConsolePath){
|
||||
this.errConsolePath = errConsolePath;
|
||||
}
|
||||
public String getErrConsolePath()
|
||||
{
|
||||
return this.errConsolePath;
|
||||
}
|
||||
public void setJenkinsConfigXmlPath(String jenkinsConfigXmlPath) {
|
||||
this.jenkinsConfigXmlPath = jenkinsConfigXmlPath;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,11 @@ public class PipeLineConfig {
|
|||
private List<String> pipelineTemplateFileName;
|
||||
private List<String> mainContainer;
|
||||
private List<String> replaceExecuteCommand;
|
||||
private String buildDuration;//超过buildDuration就认为任务超时
|
||||
|
||||
|
||||
public String getBuildDuration(){return buildDuration;};
|
||||
public void setBuildDuration(String buildDuration){this.buildDuration = buildDuration;};
|
||||
/**
|
||||
* @return the environment
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
<context:component-scan base-package="com.educoder.jenkins.api" />
|
||||
<context:component-scan base-package="com.educoder.jenkins.settings" />
|
||||
<context:component-scan base-package="com.educoder.jenkins.controller" />
|
||||
<context:component-scan base-package="com.educoder.jenkins.service" />
|
||||
|
||||
|
||||
<!--导入配置 -->
|
||||
|
@ -25,7 +26,7 @@
|
|||
<value>Java</value>
|
||||
<value>Python</value>
|
||||
<value>JDBC</value>
|
||||
<value>G++</value>
|
||||
<value>C++</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
@ -43,7 +44,7 @@
|
|||
<value>javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/</value>
|
||||
<value>null</value>
|
||||
<value>javac -encoding UTF-8 -Djava.ext.dirs=./lib/ -sourcepath src/ -d target/</value>
|
||||
<value>g++ </value>
|
||||
<value>g++</value>
|
||||
</list>
|
||||
</property>
|
||||
<property name="executeCommand">
|
||||
|
@ -51,7 +52,7 @@
|
|||
<value>java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/</value>
|
||||
<value>python </value>
|
||||
<value>java -Dfile.encoding=UTF-8 -Djava.ext.dirs=./lib/ -cp target/</value>
|
||||
<value></value>
|
||||
<value>./</value>
|
||||
</list>
|
||||
</property>
|
||||
|
||||
|
@ -98,6 +99,7 @@
|
|||
<value>.java# #src/# </value>
|
||||
<value>.py#.py</value>
|
||||
<value>.java# #src/# </value>
|
||||
<value>.cpp#.cpp</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
if (currentChallenge == CHALLENGESTAGE) {
|
||||
|
||||
//生成编译文件路径,c++编译多文件可以使用g++ /*.cpp这种形式把所有的cpp全部编译
|
||||
compileFile = new StringBuilder('CHALLENGEPROGRAMNAME');
|
||||
lastPositon = compileFile.lastIndexOf('/');
|
||||
compileFile = compileFile.substring(0,lastPositon+1) + '*.cpp';
|
||||
compileResult = ''
|
||||
try
|
||||
{
|
||||
// 编译程序
|
||||
sh script: 'COMPILECOMMAND CHALLENGEPROGRAMNAME -o executeFile.out > compile_result_CHALLENGESTAGE.out 2>&1'
|
||||
sh script: 'COMPILECOMMAND ' + compileFile + ' -o executeFile.out > compile_result_CHALLENGESTAGE.out 2>&1'
|
||||
} catch(err)
|
||||
{
|
||||
//resubmit是以字符串的形式传进来的
|
||||
//重复构建时需要删除之前构建的成功的class并catch掉class文件不存在的异常
|
||||
catchError{
|
||||
sh 'rm stepCHALLENGESTAGE/*.class'
|
||||
sh 'rm executeFile.out'
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,7 +44,7 @@ if (currentChallenge == CHALLENGESTAGE) {
|
|||
|
||||
catchError
|
||||
{
|
||||
sh script: 'EXECUTECOMMAND SOURCECLASSNAME < ../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in > actual_result_CHALLENGESTAGE_' + i + '.out 2>&1 '
|
||||
sh script: 'EXECUTECOMMANDexecuteFile.out < ../testCases/TRAININGID/CHALLENGESTAGE/' + i + '.in > actual_result_CHALLENGESTAGE_' + i + '.out 2>&1 '
|
||||
}
|
||||
|
||||
def outI = readFile 'actual_result_CHALLENGESTAGE_' + i + '.out'
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
# trustieUrl=http://ucloudtest.trustie.net/shixuns/training_task_status
|
||||
#trustie
|
||||
#online
|
||||
trustieUrl=http://bdweb.trustie.net/myshixuns/training_task_status
|
||||
#trustieUrl=http://10.9.153.195:8888/myshixuns/training_task_status
|
||||
#test
|
||||
#trustieUrl=http://testbdweb.trustie.net/myshixuns/training_task_status#test
|
||||
trustieUrl=http://testbdweb.trustie.net/myshixuns/training_task_status#test
|
||||
#jenkinsUrl
|
||||
#jenkinsUrl=http://localhost:8080/
|
||||
#jenkisUserName=admin
|
||||
#jenkisPassWord=wang199637
|
||||
#jenkinsUrl=http://123.59.135.74:9999/jenkins
|
||||
#online
|
||||
jenkinsUrl=http://106.75.78.183:8888
|
||||
#jenkinsUrl=http://10.9.184.140:8888
|
||||
#test
|
||||
#jenkinsUrl=http://106.75.96.108:8888
|
||||
jenkinsUrl=http://106.75.96.108:8888
|
||||
jenkisUserName=root
|
||||
jenkisPassWord=root
|
||||
#jenkinsUrl=http://192.168.0.238:9999
|
||||
|
@ -21,5 +21,7 @@ jenkisPassWord=root
|
|||
#jenkisPassWord=123456
|
||||
poolSize=6
|
||||
jenkinsConfigXmlPath=/var/lib/jenkins/config.xml
|
||||
#job构建失败时将控制台的错误信息输出到errConsole.txt
|
||||
errConsolePath=jobFailure
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
|
||||
trustieUrl=http://10.9.67.91:8890/myshixuns/training_task_status#test
|
||||
|
||||
jenkinsUrl=http://10.9.81.28:8888
|
||||
|
||||
jenkisUserName=root
|
||||
jenkisPassWord=root
|
||||
|
||||
poolSize=6
|
||||
jenkinsConfigXmlPath=/var/lib/jenkins/config.xml
|
||||
#job构建失败时将控制台的错误信息输出到errConsole.txt
|
||||
errConsolePath=jobFailure
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ def postGameInstanceResultToBDWeb(def arg){
|
|||
def s = 'compileResult=' + arg.compileResult + '&out=' + arg.out +
|
||||
'&in=' + arg.in + '&expectedOut=' + arg.expectedOut + '&isPublic=' + arg.isPublic
|
||||
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM',
|
||||
httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9201/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}&reSubmit=${resubmit}"
|
||||
httpMode: 'POST', requestBody: s, url: BRIDGE_URL+"/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}&reSubmit=${resubmit}"
|
||||
|
||||
if (response.status==299){
|
||||
error response.content
|
||||
|
|
|
@ -30,7 +30,8 @@ def postGameInstanceResultToBDWeb(def arg){
|
|||
def s = 'compileResult=' + arg.compileResult + '&out=' + arg.out +
|
||||
'&in=' + arg.in + '&expectedOut=' + arg.expectedOut + '&isPublic=' + arg.isPublic
|
||||
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM',
|
||||
httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9201/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}&reSubmit=${resubmit}"
|
||||
//httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9201/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}&reSubmit=${resubmit}"
|
||||
httpMode: 'POST', requestBody: s, url: BRIDGE_URL+"/jenkins-exec/pipeline/postTrainingGameInstanceResultToBDWeb?buildID=${buildID}&reSubmit=${resubmit}"
|
||||
|
||||
if (response.status==299){
|
||||
error response.content
|
||||
|
@ -42,6 +43,7 @@ def postErrorToBDWeb(def arg){
|
|||
def response = httpRequest acceptType: 'APPLICATION_JSON_UTF8', consoleLogResponseBody: true, contentType: 'APPLICATION_FORM',
|
||||
httpMode: 'POST', requestBody: s, url: "http://123.59.135.74:9201/jenkins-exec/pipeline/postErrToBDWeb?buildID=${buildID}"
|
||||
|
||||
|
||||
if (response.status==299){
|
||||
error response.content
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### 设置###
|
||||
|
||||
log4j.rootLogger = DEBUG,stdout,logDailyFile
|
||||
log4j.logger.org.apache.http.client=INFO
|
||||
log4j.logger.org.apache.http.client=ERROR
|
||||
### 输出信息到控制抬 ###
|
||||
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
|
||||
log4j.appender.stdout.Target = System.out
|
||||
|
@ -22,3 +22,13 @@ log4j.appender.logDailyFile.File = ../logs/test.log
|
|||
log4j.appender.logDailyFile.DatePattern = '.'yyyy-MM-dd
|
||||
log4j.appender.logDailyFile.Encoding = UTF-8
|
||||
|
||||
log4j.appender.logDailyFile = org.apache.log4j.DailyRollingFileAppender
|
||||
log4j.appender.logDailyFile.layout = org.apache.log4j.PatternLayout
|
||||
log4j.appender.logDailyFile.layout.ConversionPattern = %n%-d{yyyy-MM-dd HH:mm:ss}%n[%p]-[Thread: %t]-[%C.%M()]: %m%n
|
||||
log4j.appender.logDailyFile.Threshold = ERROR
|
||||
log4j.appender.logDailyFile.ImmediateFlush = TRUE
|
||||
log4j.appender.logDailyFile.Append = TRUE
|
||||
log4j.appender.logDailyFile.File = ../logs/error.log
|
||||
log4j.appender.logDailyFile.DatePattern = '.'yyyy-MM-dd
|
||||
log4j.appender.logDailyFile.Encoding = UTF-8
|
||||
|
||||
|
|
|
@ -3,4 +3,8 @@ remoteWorkspace=/home/jenkins/workspace
|
|||
java_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'openjdk', image: 'openjdk:latest', ttyEnabled: true, command: 'cat')],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')])
|
||||
python_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'python', image: 'python:latest', ttyEnabled: true, command: 'cat')],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')])
|
||||
jdbc_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'openjdk', image: 'openjdk:latest', ttyEnabled: true, command: 'cat'), containerTemplate(name: 'mysql', image: 'mysql57:latest', ttyEnabled: true, command: '/start.sh')],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')])
|
||||
gcc_podTemplate=
|
||||
<<<<<<< HEAD
|
||||
gcc_podTemplate=
|
||||
=======
|
||||
gcc_podTemplate=podTemplate(label: 'PODLABEL', containers: [containerTemplate(name: 'python', image: 'python:latest', ttyEnabled: true, command: 'cat')],volumes:[hostPathVolume(hostPath: '${workspace}', mountPath: '${remoteWorkspace}')])
|
||||
>>>>>>> fbc06d7a3fa687a33dcafcce959c9e6e1060a22e
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.lqk.test;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import com.offbytwo.jenkins.model.Computer;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import com.offbytwo.jenkins.model.LabelWithDetails;
|
||||
public class GetContainer {
|
||||
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException
|
||||
{
|
||||
JenkinsServer jenkins = new JenkinsServer(new URI("http://106.75.78.183:8888/"), "root", "root");
|
||||
/* Map<String, Computer> computer = jenkins.getComputers();
|
||||
System.out.println(computer);
|
||||
JobWithDetails jobWithDetails = jenkins.getJob("myshixun_220").details();
|
||||
jobWithDetails.getClient();*/
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.lqk.test;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.educoder.jenkins.service.BuildThread;
|
||||
import org.junit.Test;
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import com.offbytwo.jenkins.model.Build;
|
||||
import com.offbytwo.jenkins.model.BuildChangeSet;
|
||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||
import com.offbytwo.jenkins.model.Job;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import com.offbytwo.jenkins.model.TestReport;
|
||||
import cn.lili.test.JenkinsApi;
|
||||
import cn.lili.test.StringUtil;
|
||||
import cn.lili.test.TimeHandle;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
public class GetEnv {
|
||||
|
||||
public static void main(String args[]) throws URISyntaxException
|
||||
{
|
||||
JenkinsServer jenkins = new JenkinsServer(new URI("http://106.75.78.183:8888/"), "root", "root");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
package com.lqk.test;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.educoder.jenkins.service.JobMonitor;
|
||||
import com.educoder.jenkins.utils.HttpHelper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.educoder.jenkins.api.TrustieApi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.educoder.jenkins.service.ErrModel;
|
||||
*/
|
||||
/**
|
||||
* Created by LouAnt on 2017/5/27 0027
|
||||
* Description:
|
||||
*//*
|
||||
|
||||
public class JsonPostTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(JobMonitor.class);
|
||||
public static void main(String[]args)
|
||||
{
|
||||
JsonPostTest jsonPostTest = new JsonPostTest();
|
||||
jsonPostTest.postErrToTrustie(2222);
|
||||
|
||||
}
|
||||
public void postErrToTrustie(int errCode) {
|
||||
// TODO Auto-generated method stub
|
||||
logger.debug("*************postErrToTrustie:errCode:" + errCode);
|
||||
|
||||
|
||||
Map<String,String> map = new HashMap<String,String>();
|
||||
map.put("bridgeAnswer",errInfo);
|
||||
|
||||
try {
|
||||
commitResultToTrustie(map);
|
||||
}catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public void commitResultToTrustie(Map result){
|
||||
try {
|
||||
JSONObject object = new JSONObject(result);
|
||||
System.out.println("object:" + object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpHelper.sendPost("http://106.75.96.108:8888",result);
|
||||
}
|
||||
}
|
||||
*/
|
|
@ -0,0 +1,19 @@
|
|||
package com.lqk.test;
|
||||
|
||||
public class RandomTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
String pipeline = "node () {\n"
|
||||
+ " writeFile file: '../testCases/' + trainingID + '/' + challengeStage + '/' + caseID + '.in', text: input.replace('\\r\\n','\\n')\n"
|
||||
+ " writeFile file: '../testCases/' + trainingID + '/' + challengeStage + '/' + caseID + '.out', text: output.replace('\\r\\n" +
|
||||
"','\\n')\n"
|
||||
+ " writeFile file: '../testCases/' + trainingID + '/' + challengeStage + '/' + caseID + '.isPublic', text: isPublic.replace('\\r\\n" +
|
||||
"','\\n')\n"
|
||||
+ "}";
|
||||
|
||||
System.out.println(pipeline);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.lqk.test;
|
||||
import java.util.regex.*;
|
||||
public class RegexTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
String src = "I love ,回传成功 ...... like\n ng all the way,Finished:\n SUCCESS,,";
|
||||
//String Regex = "(I ([\\s\\S]*) codi([\\s\\S]*))|(([\\s\\S]*)all([\\s\\S]*)) ";
|
||||
//String Regex = "(I ([\\s\\S]*) codi([\\s\\S]*))|(([\\s\\S]*)all([\\s\\S]*)) ";
|
||||
String Regex = "([\\s\\S]*)回传成功([\\s\\S]*)Finished:([\\s\\S]*) SUCCESS([\\s\\S]*)";
|
||||
boolean result=Pattern.compile(Regex).matcher(src).find();
|
||||
System.out.println(result);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @author liliy 版本 : <版本> 修改时间: 2017年3月16日 修改内容: <修改内容>
|
||||
*/
|
||||
package cn.lili.test;
|
||||
package com.lqk.test;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -18,14 +18,18 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import com.educoder.jenkins.controller.BuildThread;
|
||||
import com.educoder.jenkins.service.BuildThread;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.offbytwo.jenkins.JenkinsServer;
|
||||
import com.offbytwo.jenkins.model.Build;
|
||||
import com.offbytwo.jenkins.model.BuildChangeSet;
|
||||
import com.offbytwo.jenkins.model.BuildWithDetails;
|
||||
import com.offbytwo.jenkins.model.Job;
|
||||
import com.offbytwo.jenkins.model.JobWithDetails;
|
||||
import com.offbytwo.jenkins.model.TestReport;
|
||||
import cn.lili.test.JenkinsApi;
|
||||
import cn.lili.test.StringUtil;
|
||||
import cn.lili.test.TimeHandle;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -39,24 +43,17 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
|
||||
public class TestLQK {
|
||||
// public String url = "http://106.75.33.219:30001";
|
||||
// public String url = "http://106.75.33.219:30001";
|
||||
// public String username = "root";
|
||||
// public String password = "root";
|
||||
// public String url = "http://123.59.135.74:9999/jenkins";
|
||||
// public String username = "guange";
|
||||
// public String password = "123456";
|
||||
public static String url = "http://106.75.78.183:8888/";
|
||||
public static String username = "root";
|
||||
public static String password = "root";
|
||||
// public static String url = "http://106.75.96.108:8888/";
|
||||
// public static String username = "root";
|
||||
// public static String password = "root";
|
||||
|
||||
// public String url = "http://106.75.78.183:9999/jenkins";
|
||||
// public String username = "guange";
|
||||
// public String password = "123456";
|
||||
|
||||
|
||||
// public String url = "http://123.59.135.74:9999/jenkins";
|
||||
// public String username = "guange";
|
||||
// public String password = "123456";
|
||||
public String time=TimeHandle.printNowTime().replace('/', '-').replace(":", "-");
|
||||
// public String fileName1=time+"-series.txt";
|
||||
// public String fileName2=time+"-parallel.txt";
|
||||
|
@ -64,64 +61,41 @@ public class TestLQK {
|
|||
// public String filePath=System.getProperty("user.dir")+"\\"+fileName1;
|
||||
|
||||
public String filePath=System.getProperty("user.dir")+"\\"+fileName2;
|
||||
private static final Logger logger = LoggerFactory.getLogger(BuildThread.class);
|
||||
public static void main(String[] args) throws IOException, URISyntaxException {
|
||||
|
||||
// try {
|
||||
JenkinsServer jenkins = new JenkinsServer(new URI("http://106.75.78.183:8888/"), "root", "root");
|
||||
private static final Logger logger = LoggerFactory.getLogger(TestLQK.class);
|
||||
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException {
|
||||
// try {http://106.75.78.183:8888 。//http://106.75.96.108:8888
|
||||
JenkinsServer jenkins = new JenkinsServer(new URI("http://106.75.96.108:8888/"), "root", "root");
|
||||
Map<String, Job> jobs = jenkins.getJobs();
|
||||
|
||||
JobWithDetails job = jobs.get("myshixun_220").details();
|
||||
Map params = new HashMap();
|
||||
params.put("buildID", "111111111111111111111111");
|
||||
params.put("instanceChallenge", "1");
|
||||
//job.build(params);
|
||||
// if(job.hasLastBuildRun())
|
||||
// System.out.println("已经构建完成");
|
||||
// else {
|
||||
// System.out.println("尚未构建完成");
|
||||
// }
|
||||
|
||||
/* while (true) {*/
|
||||
// try {
|
||||
// System.out.println("开始判断状态");
|
||||
try{
|
||||
Thread.sleep(3000);
|
||||
}catch(InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
BuildWithDetails buildWithDetails = job.getLastBuild().details();
|
||||
if(finished())
|
||||
System.out.println("正在构建");;
|
||||
boolean finished = buildWithDetails.isBuilding();
|
||||
if (finished) {
|
||||
System.out.println("仍在构建");
|
||||
// continue;
|
||||
} else {
|
||||
|
||||
System.out.println("构建完成");
|
||||
break;
|
||||
}
|
||||
}
|
||||
//
|
||||
// System.out.println("到这了");
|
||||
// }catch(Exception e){
|
||||
// System.out.println("222222");
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
/* System.out.println(System.getProperty("user.dir"));*/
|
||||
// } catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
JobWithDetails job = jobs.get("myshixun_649").details();
|
||||
//job.build();
|
||||
BuildWithDetails buildWithDetails = job.getLastBuild().details();
|
||||
System.out.println("buildNum: " + buildWithDetails.getNumber());
|
||||
return;
|
||||
/* Thread.currentThread().sleep(7000);
|
||||
//jenkins.disableJob("myshixun_220");
|
||||
//System.out.println("已将job停止");
|
||||
//Thread.currentThread().sleep(10000);
|
||||
Map<String, Job> jobs3 = jenkins.getJobs();
|
||||
*//*jenkins.disableJob("myshixun_220");*//*
|
||||
JobWithDetails job3 = jobs3.get("myshixun_220").details();
|
||||
BuildWithDetails buildWithDetails3 = job3.getLastBuild().details();
|
||||
buildWithDetails3.Stop();
|
||||
return;*/
|
||||
/* while(true){
|
||||
Map<String, Job> jobs2 = jenkins.getJobs();
|
||||
jenkins.disableJob("myshixun_220");
|
||||
JobWithDetails job2 = jobs2.get("myshixun_220").details();
|
||||
BuildWithDetails buildWithDetails2 = job2.getLastBuild().details();
|
||||
if(buildWithDetails2.isBuilding())
|
||||
System.out.println("正在构建");
|
||||
else System.out.println("没在构建");
|
||||
String consoleOutput = buildWithDetails2.getConsoleOutputText();
|
||||
System.out.println(consoleOutput);
|
||||
System.out.println("一次获取结束");
|
||||
Thread.currentThread().sleep(6000);
|
||||
String consoleOutput = buildWithDetails.getConsoleOutputText();
|
||||
System.out.println(consoleOutput);
|
||||
}*/
|
||||
}
|
||||
|
||||
public static boolean finished() throws URISyntaxException, IOException {
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue