Commit ca1b56c3 authored by 黎博's avatar 黎博

优化

parent ee24c4e9
......@@ -52,8 +52,8 @@ public class PipelineServiceImpl extends ServiceImpl<PipelineMapper, Pipeline> i
if (pipeline != null) {
if (pipeline.getEnable() == 1) {
log.info("pipeline中找到对应项目,且项目是启动状态,开始构建:{}", pipeline.toString());
jenkinsService.buildJenkinsJob(pipeline.getServiceType(), projectName, branch, pipeline.getNamespace());
String markdown = DingdingUtils.buildPipelineMarkdownMsg(projectName, branch, author, message, commitDate, pipeline.getNamespace());
Integer buildNum = jenkinsService.buildJenkinsJob(pipeline.getServiceType(), projectName, branch, pipeline.getNamespace());
String markdown = DingdingUtils.buildPipelineMarkdownMsg(projectName, branch, pipeline.getServiceType(), author, message, commitDate, pipeline.getNamespace(), buildNum.toString());
DingdingUtils.sendToDingding(markdown, dingRobotService.getById(pipeline.getDingRobotId()).getDingUrl());
} else {
log.info("pipeline中找到项目,但是项目状态为不启用,因此不构建!");
......
......@@ -166,7 +166,8 @@ public class DingdingUtils {
* @param namespace 环境
* @return
*/
public static String buildPipelineMarkdownMsg(String serviceName, String serviceBranch, String creator, String commitMsg, String date, String namespace) {
public static String buildPipelineMarkdownMsg(String serviceName, String serviceBranch, String serviceType,
String creator, String commitMsg, String date, String namespace, String buildNum) {
String title = "测试环境自动构建提醒";
String content = "> 项目名称:" + serviceName + "\n\n"
+ "> 分支名称:" + serviceBranch + "\n\n"
......@@ -174,7 +175,7 @@ public class DingdingUtils {
+ "> 触发同学:" + creator + "\n\n"
+ "> 触发信息:" + commitMsg + "\n\n"
+ "> 触发时间:" + date + "\n\n"
+ "[查看详情](" + "" + ")";
+ "[查看详情](" + "http://172.29.1.15:8080/view/TKE/job/" + "tke-" + serviceType + "/" + buildNum + "/console" + ")";
return buildMarkdownMsg(title, content, false);
}
......
......@@ -52,19 +52,19 @@ public class JenkinsService {
* @param namespace 部署的环境
* @return
*/
public void buildJenkinsJob(String type, String project, String branch, String namespace) {
public int buildJenkinsJob(String type, String project, String branch, String namespace) {
Map<String, String> buildParams = new HashMap<>();
buildParams.put("GIT_REPO", project);
buildParams.put("BRANCH_NAME", branch);
buildParams.put("DEPLOY", "true");
buildParams.put("NAMESPACE", namespace);
try {
QueueReference queueReference = jenkinsServer.getJob("tke-" + type).build(buildParams);
// Thread.sleep(5000);
Build build = jenkinsServer.getBuild(jenkinsServer.getQueueItem(queueReference));
System.out.println(build.getNumber());
jenkinsServer.getJob("tke-" + type).build(buildParams);
Build build = jenkinsServer.getJob("tke-" + type).getLastBuild();
return build.getNumber() + 1;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
......@@ -168,7 +168,7 @@ public class JenkinsService {
// System.out.println(buildResult);
// }
// System.out.println(userList.size());
jenkinsApi.buildJenkinsJob("java", "holmes", "pipline", "fe");
System.out.println(jenkinsApi.buildJenkinsJob("ui", "qa-platform-ui", "xiaotong", "fe"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment