詹金斯 + 声纳 + github 集成 [英] jenkins + sonar + github integration
问题描述
问题:我正在设置 jenkins + sonar + github 集成,以便通过声纳自动检查 pullrequest 静态代码.
我的配置:
使用 github 安装 Sonar
安装的詹金斯
在 jenkins 构建后操作中,我具有以下属性
<块引用>
-Dsonar.github.login=bhuwang-Dsonar.github.repository=公司/repo-Dsonar.verbose=true-Dsonar.analysis.mode=预览-Dsonar.issuesReport.console.enable=true-Dsonar.forceUpdate=true-Dsonar.github.login=git用户名-Dsonar.github.oauth=token
- 令牌是从我的 github 帐户生成的.
在这个
我已经添加了除了 sonar.github.pullRequest 属性之外的所有属性.我不知道如何动态获取这个属性值.看来以上四个属性必须正常工作.
我找到了添加属性的方法 -Dsonar.github.pullRequest=pullrequestNo
好消息是它现在可以通过硬编码的 pull request 号正常工作.但我需要动态方式来获取拉取请求号.
有谁知道如何获取拉取请求编号.在 jenkins 中动态地运行.?
我发现拉取请求生成器可以工作,但我没有运气.我无法在声纳属性中使用拉取请求构建器环境变量.
PullRequest 构建器设置
- 创建自由风格的 Jenkins 作业
将 github url 添加到 GitHub 项目部分
设置源代码管理部分
设置构建触发器
为后期构建操作设置声纳
在附加属性部分提供以下声纳属性p>
-Dsonar.sourceEncoding=UTF-8-Dsonar.analysis.mode=预览-Dsonar.github.repository=公司/repo-Dsonar.github.login=git用户名-Dsonar.github.oauth=oauthtoken-Dsonar.host.url=sonarhostedurl-Dsonar.login=admin-Dsonar.password=pass-Dsonar.github.pullRequest=${ghprbPullId}${ghprbPullId}:这将通过 github pullrequest builder 插件提供
注意: 作业应通过 pullrequest builder 插件触发,否则 ${ghprbPullId} 将返回空白.如果您手动运行作业,这将不起作用,您必须将此 ${ghprbPullId} 属性作为构建参数传递.如果您想检查可用的环境参数,请遵循此 Git用于执行 Jenkins shell 脚本的环境变量
我希望这会有所帮助.
Problem: I am setting up jenkins + sonar + github integration for automatic pullrequest static code check through sonar.
My Configuration:
Installed Sonar with github
Installed jenkins
In jenkins post-build action I have the following properties
-Dsonar.github.login=bhuwang -Dsonar.github.repository=company/repo -Dsonar.verbose=true -Dsonar.analysis.mode=preview -Dsonar.issuesReport.console.enable=true -Dsonar.forceUpdate=true -Dsonar.github.login=gitusername -Dsonar.github.oauth=token
- Token was generated from my github account.
In this link I have read that I have to provide the following properties while running sonarqube:
I have added all except sonar.github.pullRequest properties. I don't know how do I get this property value dynamically. Seems like above four properties are must to work properly.
Edit: I have found the way to add property -Dsonar.github.pullRequest=pullrequestNo
And the good news is it is working perfectly fine now with hardcoded pull request no. but I need the dynamic way to get the pull request no.
Does anyone know how to get the pull request no. dynamically inside jenkins.?
I have found that pull request builder will work but no luck at my end. I am not able to use pull request builder environment variables inside sonar properties.
https://issues.jenkins-ci.org/browse/JENKINS-24590
Finally I am able to solve this issue. Here is the detail:
- Install Sonar with GitHub plugin.
Install Jenkins with the following plugins
- GitHub Pull Request Builder
- SonarQube Plugin
- GIT plugin
- GitHub plugin
Follow this link to setup pull request builder plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin#GitHubpullrequestbuilderplugin-EnvironmentVariables
- Global Jenkins System Setup:
- Goto Manage Jenkins -> Configure System
- Configure jdk
- Install sonarQube Runner
- Configure Sonar
- Git WebHook Setup
PullRequest Builder Setup
- Create Free Style Jenkins job
add github url to GitHub Project section
Setup Source Code Management Section
Setup Build Trigger
Setup Sonar for post build actions
In the additional properties section provide the following sonar properties
-Dsonar.sourceEncoding=UTF-8 -Dsonar.analysis.mode=preview -Dsonar.github.repository=company/repo -Dsonar.github.login=gitusername -Dsonar.github.oauth=oauthtoken -Dsonar.host.url=sonarhostedurl -Dsonar.login=admin -Dsonar.password=pass -Dsonar.github.pullRequest=${ghprbPullId} ${ghprbPullId}: this will be provided via github pullrequest builder plugin
Note: The job should be triggered through pullrequest builder plugin otherwise ${ghprbPullId} will return blank. If you run the job manually this will not work for that you have to pass this ${ghprbPullId} property as a build parameter. If you want to check the environment parameter available follow this Git environment variables for use in executing Jenkins shell scripts
I hope this helps.
这篇关于詹金斯 + 声纳 + github 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!