如何将SonarCloud与GitHub和Jenkins集成

时间:2019-02-08 11:49:57

标签: jenkins github sonarcloud

我刚刚结束了与Jenkins的GitHub集成,因此每次我将代码提交到GitHub存储库时,Jenkins都会自动构建。 现在,我也尝试集成SonarCloud,但没有成功。 我不想与本地SonarQube服务器集成,我真的需要SonarCloud供我的团队在每次Jenkins构建时对其进行检查。

我不确定是否应该在本地分析项目以实现此目标,或者我是否可以分析我的Jenkins服务器或GitHub存储库并获得所需的结果,因为我找不到任何文档。

有人能指出我正确的方向吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

Sonarcloud只是一个声纳服务器。

只需使用sonar-scanner(jenkins的文档可以在here中找到。

首先,您需要安装jenkins plugin for sonar-scanner

然后,您使用var svg = d3.select("body") .append("svg") .attr("width", 500) .attr("height", 200); var g = svg.append('g') .attr('class', 'resize-me'); var rect = g.append('rect') .attr('stroke', 'blue') .attr('x', 0) .attr('y', 0) .attr("width", 200) .attr("height", 200) .attr('stroke-width', 2) .attr('stroke', 'white') .attr('fill', 'grey'); var image = g.append('image') .attr('x', 0) .attr('y', 0) .attr('width', 128) .attr('height', 128) .attr("xlink:href", imageUrl); interact('.resize-me') .resizable({ edges: { left: true, right: true, bottom: true, top: true } }) .on('resizemove', function(event) { var target = event.target; var rect = target.childNodes[0]; var img = target.childNodes[1]; var x = (parseFloat(target.getAttribute('endx')) || 0) var y = (parseFloat(target.getAttribute('endy')) || 0) rect.setAttribute('width', event.rect.width); rect.setAttribute('height', event.rect.height); x += event.deltaRect.left y += event.deltaRect.top rect.setAttribute('transform', 'translate(' + x + ', ' + y + ')') rect.setAttribute('endx', x) rect.setAttribute('endy', y) // clip image svg.append('defs') .append('clipPath') .attr('id', 'clip2') .append('rect') .attr('x', 0) .attr('y', 0) .attr('width', event.rect.width) .attr('height', event.rect.height); image.attr("clip-path", "url(#clip2)"); }); 打开声纳扫描仪的配置。

Manage Jenkins > Configure System下插入https://sonarcloud.io,在Server URL下插入您的声纳令牌(声纳)

image showing how to configure it

Server authentication token下,您应检查Manage Jenkins > Configure System,在工作中的Enable injection of SonarQube server configuration as build environment variables中,应启用Build Environment

完成此操作后,可以使用Prepare SonarScanner environment(如果使用maven),$SONAR_MAVEN_GOAL(如果使用gradle)或./gradlew sonarqube(如果您什么都不用。

相关问题