96SEO 2026-02-19 10:35 0
公司自研CI/DI平台借助JenkinsSonarQube进行代码质量管理。

对接版本
Java对接Jenkins有第三方组件比如jenkins-rest、jenkins-client但是考虑到第三方组件会引入其他jar包而且会存在漏洞问题。
到时候升级组件时可能会和项目框架本身使用的第三方jar起冲突。
因此使用jenkins-cli来实现自己的需求。
注意这里不是单纯的使用java
而且提取并修改jenkins-cli.jar中的源码来达到自身需求开发的目的。
比如创建View时使用jenkins-cli.jar时需要传入xml内容标准输入流
所以我们进行了改造可以支持传入byte数组的形式使用体验更符合大众。
jenkins-cli.jar的源码修改
com.infosec.autobuild.util;import
com.cdancy.jenkins.rest.JenkinsClient;
com.cdancy.jenkins.rest.domain.job.BuildInfo;
com.cdancy.jenkins.rest.domain.queue.QueueItem;
com.infosec.autobuild.dto.jenkins.BuildInfoDto;
com.infosec.autobuild.dto.jenkins.CredentialDto;
com.infosec.autobuild.dto.jenkins.JobDto;
com.infosec.autobuild.dto.jenkins.ViewDto;
com.infosec.autobuild.hudson.cli.CLI;
org.apache.http.auth.AuthScope;
org.apache.http.auth.UsernamePasswordCredentials;
org.apache.http.client.AuthCache;
org.apache.http.client.CredentialsProvider;
org.apache.http.client.methods.CloseableHttpResponse;
org.apache.http.client.methods.HttpGet;
org.apache.http.client.protocol.HttpClientContext;
org.apache.http.impl.auth.BasicScheme;
org.apache.http.impl.client.BasicAuthCache;
org.apache.http.impl.client.BasicCredentialsProvider;
org.apache.http.impl.client.CloseableHttpClient;
org.apache.http.impl.client.HttpClients;
org.apache.http.util.EntityUtils;
org.springframework.beans.BeanUtils;
org.springframework.util.CollectionUtils;
org.springframework.util.ObjectUtils;
org.springframework.util.StringUtils;import
java.nio.charset.StandardCharsets;
system::system::jenkins等同于SystemCredentialsProvider::SystemContextResolver::jenkins*
list-credentials-context-resolvers获取*/private
Credentials集合:list-credentials*/LIST_CREDENTIALS(list-credentials,
Credentials集合返回xml:list-credentials-as-xml*/LIST_CREDENTIALS_AS_XML(list-credentials-as-xml,
Credentials:create-credentials-by-xml*/CREATE_CREDENTIALS(create-credentials-by-xml,
Credentials:create-credentials-by-xml*/UPDATE_CREDENTIALS(update-credentials-by-xml,
Credentials:delete-credentials*/DELETE_CREDENTIALS(delete-credentials,
Credentials:get-credentials-as-xml*/GET_CREDENTIALS(get-credentials-as-xml,
Credentials),;SetterGetterprivate
{this.setOp(op);this.setDesc(desc);}}/***
Jenkins地址比如http://10.100.57.156:8080*
(!StringUtils.hasText(credentialDto.getId()))
{credentialDto.setId(UUID.randomUUID().toString());}String
CredentialDto.parseDto2Xml(credentialDto);CLI
String[]{Operation.CREATE_CREDENTIALS.op,
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildErrorDto().msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
String[]{Operation.DELETE_CREDENTIALS.op,
msg.contains(CREDENTIAL_NOT_FOUND))
ResultDto.buildSuccessDto();}return
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildErrorDto().msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
(!StringUtils.hasText(credentialDto.getId()))
ResultDto.buildErrorDto().msg(凭证id不能为空);}String
CredentialDto.parseDto2Xml(credentialDto);CLI
String[]{Operation.UPDATE_CREDENTIALS.op,
msg.contains(CREDENTIAL_NOT_FOUND))
ResultDto.buildErrorDto().msg(msg);}return
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildErrorDto().msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
String[]{Operation.GET_CREDENTIALS.op,
msg.contains(CREDENTIAL_NOT_FOUND))
ResultDto.buildErrorDto().msg(msg);}boolean
ResultDto.SUCCESS.equals(String.valueOf(code));CredentialDto
{CredentialDto.parseXmlStr2Dto(credentialDto,
ResultDto.buildSuccess(credentialDto)
ResultDto.buildError(credentialDto).msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
String[]{Operation.LIST_CREDENTIALS_AS_XML.op,
SYSTEM_STORE_ID},PROTOCOL_HTTP,
ResultDto.SUCCESS.equals(String.valueOf(code));if
{CredentialDto.parseXmlStr2List(credentialDtoList,
ResultDto.buildSuccess(credentialDtoList)
ResultDto.buildError(credentialDtoList).msg(msg);}/***
host/job/jobName/buildId/api/json;private
host/job/jobName/buildId/api/json;enum
Job添加到视图中*/ADD_TO_VIEW(add-job-to-view,
Job从视图中移除*/REMOVE_FROM_VIEW(remove-job-from-view,
{this.setOp(op);this.setDesc(desc);}}/***
Jenkins地址比如http://10.100.57.156:8080*
String[]{Operation.LIST.op};String[]
Stream.concat(Arrays.stream(baseArgs),Arrays.stream(new
String[]{viewName})).toArray(String[]::new)
ResultDto.SUCCESS.equals(String.valueOf(code));boolean
JobDto();jobDto.setJobName(tmp);jobDto.setViewName(listAllJobs
);jobDtoList.add(jobDto);}}}return
ResultDto.buildSuccess(jobDtoList)
ResultDto.buildError(jobDtoList).msg(msg);}/***
String[]{Operation.ADD_TO_VIEW.op};String[]
jobNames).flatMap(Arrays::stream).toArray(String[]::new);CLI
ResultDto.SUCCESS.equals(String.valueOf(code))
?ResultDto.buildSuccess(jobDtoList)
ResultDto.buildError(jobDtoList).msg(msg);}public
String[]{Operation.REMOVE_FROM_VIEW.op};String[]
jobNames).flatMap(Arrays::stream).toArray(String[]::new);CLI
ResultDto.SUCCESS.equals(String.valueOf(code))
?ResultDto.buildSuccess(jobDtoList)
ResultDto.buildError(jobDtoList).msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
job.getSvnInfoList();ListJobDto.GitInfoDto
CollectionUtils.isEmpty(svnInfoDtoList)
CollectionUtils.isEmpty(gitInfoDtoList);if
ResultDto.buildErrorDto().msg(源码管理地址信息不能为空);}String
keepDependenciesfalse/keepDependencies\n
(!CollectionUtils.isEmpty(svnInfoDtoList))
(!CollectionUtils.isEmpty(gitInfoDtoList))
excludedRegions/excludedRegions\n
includedRegions/includedRegions\n
excludedRevprop/excludedRevprop\n
excludedCommitMessages/excludedCommitMessages\n
class\hudson.scm.subversion.UpdateUpdater\/\n
ignoreDirPropChangesfalse/ignoreDirPropChanges\n
filterChangelogfalse/filterChangelog\n
quietOperationtrue/quietOperation\n
blockBuildWhenDownstreamBuildingfalse/blockBuildWhenDownstreamBuilding\n
blockBuildWhenUpstreamBuildingfalse/blockBuildWhenUpstreamBuilding\n
concurrentBuildfalse/concurrentBuild\n;xml
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildErrorDto().msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
jobNames).flatMap(Arrays::stream).toArray(String[]::new);return
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
JobDto();jobDto.setJobName(jobName);//解析xml获取名称、描述等信息String
ObjectUtils.isEmpty(resultDto.getData())
resultDto.getData().toString();if
{jobDto.parseXmlStr2Dto(msg);}return
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
String[]{buildId.toString()}).flatMap(Arrays::stream).toArray(String[]::new);return
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
String[]{Operation.STOP_BUILDS.op},
jobNames).flatMap(Arrays::stream).toArray(String[]::new);return
Jenkins地址比如http://10.100.57.156:8080*
ResultDto.buildErrorDto().msg(buildId
JenkinsClient.builder().endPoint(host).credentials(username
password).build();ListQueueItem
client.api().queueApi().queue();for
item.task().name());}System.out.println(JsonUtil.toJSONString(client.api().systemApi().systemInfo()));BuildInfo
client.api().jobsApi().buildInfo(null,
buildId);System.out.println(data.building());String
JOB_BUILD_DETAIL_URL.replace(host,
Jenkins地址比如http://10.100.57.156:8080*
IllegalArgumentException(buildId
JOB_BUILD_DETAIL_URL.replace(host,
buildId.toString());BuildInfoDto
Jenkins地址比如http://10.100.57.156:8080*
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildError(msg).msg(msg);}/***
class\hudson.scm.SubversionSCM\
hudson.scm.SubversionSCM_-ModuleLocation\n).append(
svnInfoDto.getIgnoreExternalsOption()
/ignoreExternalsOption\n).append(
svnInfoDto.getCancelProcessOnExternalsFail()
/cancelProcessOnExternalsFail\n).append(
/hudson.scm.SubversionSCM_-ModuleLocation\n);}xml
job.getBuildCmdList();ListJobDto.SonarRunnerBuilderDto
job.getSonarRunnerBuilderDtoList();boolean
CollectionUtils.isEmpty(shellList)
CollectionUtils.isEmpty(sonarRunnerBuilderDtoList);if
(!CollectionUtils.isEmpty(shellList))
shellList.stream().collect(Collectors.joining(\n));xml
(!CollectionUtils.isEmpty(sonarRunnerBuilderDtoList))
projectInfo.getBuildVersion();StringBuilder
hudson.plugins.sonar.SonarRunnerBuilder\n).append(
\n).append(sonar.projectVersion
sonar.getSonarScannerLanguage()
\n).append(sonar.sourceEncodingUTF-8\n).append(sonar.java.binariestarget/classes\n).append(sonar.sources.\n).append(sonar.login
sonar.getSonarScmDisabled()).append(
/additionalArguments\n).append(
/hudson.plugins.sonar.SonarRunnerBuilder\n);}xml
创建Jenkins视图*/CREATE(create-view,
更新Jenkins视图*/UPDATE(update-view,
删除Jenkins视图*/DELETE(delete-view,
查询Jenkins视图);SetterGetterprivate
{this.setOp(op);this.setDesc(desc);}}/***
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
(!StringUtils.hasText(viewName))
ResultDto.buildErrorDto().msg(视图名称不能为空);}CLI
ResultDto.SUCCESS.equals(String.valueOf(code));ViewDto
ViewDto();viewDto.setViewName(viewName);//解析xml获取view名称、描述、关联的job等信息if
{viewDto.parseXmlStr2Dto(msg);}if
(ObjectUtils.isEmpty(returnJobDetails))
jobName).getData();BeanUtils.copyProperties(dto,
ResultDto.buildSuccess(viewDto)
ResultDto.buildError(viewDto).msg(msg);}/***
Jenkins地址比如http://10.100.57.156:8080*
(!oldViewInfoResult.ifSuccess())
oldViewInfoResult.getData();BeanUtils.copyProperties(oldViewInfo,
newViewInfo);newViewInfo.setViewName(newViewName);//2、拷贝目标View内容并重命名ResultDto
(CollectionUtils.isEmpty(jobDtoList))
jobDtoList.get(i).getJobName();}ResultDto
(!addJob2ViewResult.ifSuccess())
ResultDto.buildSuccessDto();}}/***
Jenkins地址比如http://10.100.57.156:8080*
操作create-view、update-view、delete-view*
class\hudson.model.View$PropertyList\/\n
class\java.lang.String$CaseInsensitiveComparator\/\n
hudson.views.LastSuccessColumn/\n
hudson.views.LastFailureColumn/\n
hudson.views.LastStableColumn/\n
hudson.views.LastDurationColumn/\n
hudson.views.BuildButtonColumn/\n
jenkins.branch.DescriptionColumn
(StringUtils.hasText(viewDto.getIncludeRegex()))
Operation.UPDATE.equals(op);String[]
ResultDto.SUCCESS.equals(String.valueOf(code))
ResultDto.buildErrorDto().msg(msg);}}public
获取Jenkins版本信息*/VERSION(version,
更新Jenkins全局配置信息*/RELOAD_CONFIGURATION(reload-configuration,
builds.*/SAFE_RESTART(safe-restart,
停止Jenkins服务*/SHUTDOWN(shutdown,
Jenkins.*/SAFE_SHUTDOWN(safe-shutdown,
queue.*/CLEAR_QUEUE(clear-queue,
清除Jenkins中的构建队列),;SetterGetterprivate
{this.setOp(op);this.setDesc(desc);}}/***
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Jenkins地址比如http://10.100.57.156:8080*
Operation.RELOAD_CONFIGURATION);}/***
Jenkins地址比如http://10.100.57.156:8080*
ResultDto.SUCCESS.equals(String.valueOf(code))
?ResultDto.buildSuccessDto(successMsg)
ResultDto.buildErrorDto().msg(msg);}}/***
注意查询类时xml为空涉及到使用xml内容创建、更新操作的xml不能为空**
Jenkins地址比如http://10.100.57.156:8080*
(!StringUtils.hasText(protocol))
xml.getBytes(StandardCharsets.UTF_8);}CLI
Stream.concat(Arrays.stream(baseArgs),
Arrays.stream(args)).toArray(String[]::new);log.info(executing
JsonUtil.toJSONString(finalArgs));try
e.getMessage();log.error(executing
JsonUtil.toJSONString(finalArgs),
uri.getScheme());CredentialsProvider
BasicCredentialsProvider();credsProvider.setCredentials(new
UsernamePasswordCredentials(username,
BasicScheme();authCache.put(host,
HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();HttpGet
HttpClientContext.create();localContext.setAuthCache(authCache);if
EntityUtils.toString(response.getEntity());System.out.println(returnMsg);if
(StringUtils.hasText(returnMsg))
ResultDto.buildSuccessDto().data(data);}return
ResultDto.buildSuccessDto().data(returnMsg);}
ResultDto.buildErrorDto().data(data);}}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback