Sonarqube基础篇:property设定

Sonarqube基础篇:property设定_第1张图片
这篇文章介绍以下如何使用SonarQube(LTS的5.6.5版本)的WebApi(SonarQube的RestApi)来对Sonar进行设定。

property操作的API

sonar通过property来对设定进行管理,通过对应的api可以进行增删改查,相关的信息如下:

http方法 api 说明
GET /api/properties 获得property信息
POST /api/properties 创建与更新:通过设定id/value,比如:id=sonar.scm.disabled&value=true
DELETE /api/properties 按条件删除property,条件接其后即可

可设定内容

以下使用Sonar所提供的WebApi确认到系统可设定信息以及当前设定值如下

设定项目 缺省值
sonar.core.version, 5.6.5
sonar.qualitygate, 1
sonar.permission.template.default, default_template
sonaranalyzer-cs.nuget.packageVersion, 1.10.0
sonar.authenticator.ignoreStartupFailure, false
sonar.cs.ignoreHeaderComments, true
sonar.javascript.jQueryObjectAliases, $, jQuery
sonar.ce.maxLogsPerTask, 10
sonar.cs.fxcop.fxCopCmdPath, C
sonar.forceAuthentication, false
sonar.analysis.mode, analysis
sonar.notifications.delay, 60
sonar.allowUsersToSignUp, false
sonar.cs.fxcop.aspnet, false
sonar.authenticator.createUsers, true
sonaranalyzer-cs.ruleNamespace, SonarAnalyzer.CSharp
sonar.import_unknown_files, false
sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay, 24
sonar.dbcleaner.cleanDirectory, true
sonar.cpd.cross_project, false
sonar.enableFileVariation, false
sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByWeek, 4
sonar.timemachine.period1, previous_version
sonar.timemachine.period2, previous_analysis
sonar.timemachine.period3, 30
sonaranalyzer-cs.pluginKey, csharp
sonar.javascript.ignoreHeaderComments, true
sonar.dbcleaner.daysBeforeDeletingClosedIssues, 30
sonar.jacoco.itReportPath, target/jacoco-it.exec
sonar.dbcleaner.weeksBeforeKeepingOnlyOneSnapshotByMonth, 52
sonar.lf.gravatarServerUrl, https
sonar.violationLocale, en
sonar.cs.fxcop.timeoutMinutes, 10
sonar.squid.analyse.property.accessors, true
sonar.jacoco.reportPath, target/jacoco.exec
sonaranalyzer-cs.staticResourceName, SonarAnalyzer.zip
sonar.notifications.runningDelayBeforeReportingStatus, 600
sonar.defaultGroup, sonar-users
sonaranalyzer-cs.nuget.packageId, SonarAnalyzer.CSharp
sonar.authenticator.downcase, false
sonar.scm.disabled, false
sonar.cs.msbuild.testProjectPattern, [^\\\\]test[^\\\\]$
sonar.updatecenter.activate, true
sonaranalyzer-cs.analyzerId, SonarAnalyzer.CSharp
sonar.technicalDebt.hoursInDay, 8
sonar.technicalDebt.ratingGrid, 0.05,0.1,0.2,0.5
sonar.technicalDebt.developmentCost, 30
sonar.lf.enableGravatar, true
sonar.preview.excludePlugins, buildstability,devcockpit,pdfreport,report,views,jira,buildbreaker,scmstats
sonaranalyzer-cs.pluginVersion, 1.10.0
sonar.cs.file.suffixes, .cs
sonar.security.localUsers, admin,
sonar.skipDesign, false
sonar.javascript.file.suffixes, .js
sonar.java.file.suffixes, .java,.jav
sonar.javascript.forceZeroCoverage, false
sonar.dbcleaner.weeksBeforeDeletingAllSnapshots, 260
sonar.jacoco.reportMissing.force.zero, false
sonar.updatecenter.url, https

可以使用如下脚本来生成markdown格式的信息,可以参照

curl -u admin:admin http://localhost:9000/api/properties 2>/dev/null |jq . |egrep 'key|value' |grep -v -w values  |sed s/\"//g |awk -F: '{print $2}' |awk '{key=$0; getline; value=$0; printf("|%s|%s|\n",key,value)}'

#设定例

场景:比如希望动态修改如SCM的设定Disable the SCM Sensor,此值缺省设定为false。设定一般是使用管理权限的用户登录,通过菜单Administration -> General Settings -> SCM -> Disable the SCM Sensor 选择true,然后保存设定。

设定前确认

Sonarqube基础篇:property设定_第2张图片

设定

使用如下命令通过webapi对其进行设定,注意在命令行执行的时候&需要转义

/ # curl -u admin:admin -X POST http://localhost:9000/api/properties?id=sonar.scm.disabled\&value=true
{"err_code":200,"err_msg":"property created"}/ # 

结果确认

可以看到值已经设定为true了
Sonarqube基础篇:property设定_第3张图片

这里只是一个例子,其他相关的property,在sonarqube中也可以通过这种方式进行设定,如果在DevOps实践中需要和Sonarqube进行深度集成的情况下,可以考虑使用此种方式。

#参考内容
https://docs.sonarqube.org/pages/viewpage.action?pageId=2392170

你可能感兴趣的:(DevOps,sonarqube,DevOps系列之:自动化测试)