diff --git a/HuaweiCloud-obs-uploader.hpi b/HuaweiCloud-obs-uploader.hpi index 204d964164d92ed849b853a93cbe0876eae9218d..403ee7b22f087e4e724eb139246f79c16f5c04c8 100644 Binary files a/HuaweiCloud-obs-uploader.hpi and b/HuaweiCloud-obs-uploader.hpi differ diff --git a/README.md b/README.md index afeca58105d19ff7f817419c8cc39784564b99f7..dea8b60004676fbf929a84e7b6f4265661ee7064 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ mvn package -DskipTests ##### 片段生成器生成 -ak/sk示例1:obsUpload(ak:"...",sk:"...",endpoint:"obs.cn-south-1.myhuaweicloud.com",bucket:"obs-jenkins", includePathPattern:'***/**', path:'path/to/targetFolder/', workingDir:'/', contentType:'application/x-font-ttf', contentDisposition:'attachment',kmsId:'...') +ak/sk示例1:OBSPipelineUpload(ak:"...",sk:"...",endpoint:"obs.cn-south-1.myhuaweicloud.com",bucket:"obs-jenkins", includePathPattern:'***/**', path:'path/to/targetFolder/', workingDir:'/', contentType:'application/x-font-ttf', contentDisposition:'attachment',kmsId:'...') -密钥示例2:obsUpload acl: 'Private', ak: '', bucket: 'obs-jenkins', contentType: 'application/x-font-ttf', credentialsId: 'global-obs-credentialsId', endpoint: 'obs.cn-south-1.myhuaweicloud.com', file: '', includePathPattern: '**/*', kmsId: '.....', path: 'path/to/targetFolder/', sk: '', workingDir: 'target' +密钥示例2:OBSPipelineUpload acl: 'Private', ak: '', bucket: 'obs-jenkins', contentType: 'application/x-font-ttf', credentialsId: 'global-obs-credentialsId', endpoint: 'obs.cn-south-1.myhuaweicloud.com', file: '', includePathPattern: '**/*', kmsId: '.....', path: 'path/to/targetFolder/', sk: '', workingDir: 'target' ![上传](image/pipeline.jpg) diff --git a/src/main/java/com/huawei/jenkins/codeCheck/codeCheckPipelineStep.java b/src/main/java/com/huawei/jenkins/codeCheck/codeCheckPipelineStep.java index 66e52cdb610f49111015903ebbd91906d6efcd4b..749ad29b06884e873f27d772cc4eeccfaca1d247 100644 --- a/src/main/java/com/huawei/jenkins/codeCheck/codeCheckPipelineStep.java +++ b/src/main/java/com/huawei/jenkins/codeCheck/codeCheckPipelineStep.java @@ -84,6 +84,7 @@ public class codeCheckPipelineStep extends Step { public String getProject_id() { return project_id; } + @DataBoundSetter public void setProject_id(String project_id) { this.project_id = project_id; diff --git a/src/main/java/com/huawei/jenkins/codeCheck/codeCheckService.java b/src/main/java/com/huawei/jenkins/codeCheck/codeCheckService.java index f88f8cf53ff218befcaefb34d45e5dd8a57f2aa4..f10f5a9fea4c8f9945928a5e4405b6df3fdb6f00 100644 --- a/src/main/java/com/huawei/jenkins/codeCheck/codeCheckService.java +++ b/src/main/java/com/huawei/jenkins/codeCheck/codeCheckService.java @@ -1,3 +1,4 @@ + package com.huawei.jenkins.codeCheck; import com.google.common.base.Preconditions; @@ -18,20 +19,15 @@ import org.apache.commons.lang.StringUtils; import java.io.Serializable; - public class codeCheckService implements Serializable { private static final long serialVersionUID = 1; public static String runTask(TaskListener listener, CustomInput customInput) { inputValidate(customInput); - ICredential auth = new BasicCredentials() - .withAk(customInput.getAk()) - .withSk(customInput.getSk()); + ICredential auth = new BasicCredentials().withAk(customInput.getAk()).withSk(customInput.getSk()); - CodeCheckClient client = CodeCheckClient.newBuilder() - .withCredential(auth) - .withRegion(CodeCheckRegion.valueOf(customInput.getRegion())) - .build(); + CodeCheckClient client = CodeCheckClient.newBuilder().withCredential(auth) + .withRegion(CodeCheckRegion.valueOf(customInput.getRegion())).build(); RunTaskRequest request = new RunTaskRequest(); request.withTaskId(customInput.getTask_id()); @@ -53,7 +49,7 @@ public class codeCheckService implements Serializable { } listener.getLogger().println("检查任务执行完成!!!!"); - message = CheckRecord(client,customInput,listener); + message = CheckRecord(client, customInput, listener); } else if (response.getHttpStatusCode() == 400) { listener.getLogger().println("网络繁忙,请稍后再试"); } else { @@ -71,14 +67,13 @@ public class codeCheckService implements Serializable { return message; } - public static Integer showTasks(CodeCheckClient client, String taskId, TaskListener listener) { ShowProgressDetailRequest request = new ShowProgressDetailRequest(); request.withTaskId(taskId); ShowProgressDetailResponse response = null; try { response = client.showProgressDetail(request); - if(StringUtils.isNotBlank(response.getProgress().getRatio())){ + if (StringUtils.isNotBlank(response.getProgress().getRatio())) { listener.getLogger().println("任务进度:" + response.getProgress().getRatio()); } } catch (ConnectionException e) { @@ -92,9 +87,8 @@ public class codeCheckService implements Serializable { return response.getTaskStatus(); } - - public static String CheckRecord(CodeCheckClient client, CustomInput customInput, TaskListener listener){ - String message = ""; + public static String CheckRecord(CodeCheckClient client, CustomInput customInput, TaskListener listener) { + String message = ""; ShowTaskDetailRequest request = new ShowTaskDetailRequest(); request.withTaskId(customInput.getTask_id()); try { @@ -103,17 +97,17 @@ public class codeCheckService implements Serializable { listener.getLogger().println("严重问题数:" + info.getMajorCount()); listener.getLogger().println("常规问题数:" + info.getMinorCount()); listener.getLogger().println("提示问题数:" + info.getSuggestionCount()); - if(info.getIsAccess().equals("0")){ + if (info.getIsAccess().equals("0")) { message = "门禁质量不通过"; - }else { + } else { message = "门禁质量通过"; } - String url = "https://devcloud."+customInput.getRegion()+".huaweicloud.com/codecheck/project/"+customInput.getProject_id()+"/codecheck/task/"+customInput.getTask_id()+"/detail"; - listener.getLogger().println("关于具体详情,可在:"+url+"\n中查看"); - //发送钉钉微信通知 - if(StringUtils.isNotBlank(customInput.getTopicUrn())){ - //发送钉钉微信通知 - publishMessage(customInput,info, listener); + String url = "https://console.huaweicloud.com/devcloud/?region=" + customInput.getRegion() + "#/codecheck/list"; + listener.getLogger().println("关于具体详情,可前往:" + url + "\n查看"); + // 发送钉钉微信通知 + if (StringUtils.isNotBlank(customInput.getTopicUrn())) { + // 发送钉钉微信通知 + publishMessage(customInput, info, listener); } } catch (ConnectionException e) { e.printStackTrace(); @@ -126,31 +120,26 @@ public class codeCheckService implements Serializable { return message; } + public static void publishMessage(CustomInput customInput, ShowTaskDetailResponse info, TaskListener listener) { + ICredential auth = new BasicCredentials().withAk(customInput.getAk()).withSk(customInput.getSk()); - public static void publishMessage(CustomInput customInput,ShowTaskDetailResponse info,TaskListener listener) { - ICredential auth = new BasicCredentials() - .withAk(customInput.getAk()) - .withSk(customInput.getSk()); - - SmnClient client = SmnClient.newBuilder() - .withCredential(auth) - .withRegion(SmnRegion.valueOf(customInput.getRegion())) - .build(); + SmnClient client = SmnClient.newBuilder().withCredential(auth) + .withRegion(SmnRegion.valueOf(customInput.getRegion())).build(); PublishMessageRequest request = new PublishMessageRequest(); request.withTopicUrn(customInput.getTopicUrn()); PublishMessageRequestBody body = new PublishMessageRequestBody(); - String url = "https://devcloud."+customInput.getRegion()+".huaweicloud.com/codecheck/project/"+customInput.getProject_id()+"/codecheck/task/"+customInput.getTask_id()+"/detail"; + String url = "https://console.huaweicloud.com/devcloud/?region=" + customInput.getRegion() + "#/codecheck/list"; String message = "尊敬的华为云用户,您好:\n本次执行代码检查的结果:"; - message+="\n致命问题数:" + info.getCriticalCount(); - message+="\n严重问题数:" + info.getMajorCount(); - message+="\n常规问题数:" + info.getMinorCount(); - message+="\n提示问题数:" + info.getSuggestionCount(); - if(info.getIsAccess().equals("0")){ - message+="\n门禁质量不通过"; - }else { - message+="\n门禁质量通过"; + message += "\n致命问题数:" + info.getCriticalCount(); + message += "\n严重问题数:" + info.getMajorCount(); + message += "\n常规问题数:" + info.getMinorCount(); + message += "\n提示问题数:" + info.getSuggestionCount(); + if (info.getIsAccess().equals("0")) { + message += "\n门禁质量不通过"; + } else { + message += "\n门禁质量通过"; } - message+="\n关于具体详情,可在:"+url+"\n中查看" ; + message += "\n关于具体详情,可前往:" + url + "\n查看"; body.withMessage(message); request.withBody(body); try { @@ -165,8 +154,6 @@ public class codeCheckService implements Serializable { } } - - private static void inputValidate(CustomInput customInput) { final String ak = customInput.getAk(); final String sk = customInput.getSk(); @@ -176,8 +163,8 @@ public class codeCheckService implements Serializable { Preconditions.checkArgument(StringUtils.isNotBlank(projectId), "projectId id can not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(taskId), "task id can not be blank"); Preconditions.checkArgument(StringUtils.isNotBlank(region), "region can not be blank"); - Preconditions.checkArgument(StringUtils.isNotBlank(ak) && StringUtils.isNotBlank(sk), "Ak, Sk can not be blank"); + Preconditions.checkArgument(StringUtils.isNotBlank(ak) && StringUtils.isNotBlank(sk), + "Ak, Sk can not be blank"); } - }