Jenkins 管道作业构建

标签 jenkins sonarqube jenkins-plugins jenkins-pipeline sonarqube-scan

我正在尝试构建 Jenkins Pipeline 作业。我正在尝试将 Sonar 扫描仪配置放入 Jenkins 管道作业的 Groovy 脚本中。 Sonarqube configurations in Jenkins Pipeline Job Groovy Script

但是当我构建上述作业时,我收到以下错误 - Error

此外,当我引用 Sonarqube 文档与 Jenkins Pipeline 作业集成时,我没有得到有关设置 sonarqube 属性的信息,否则我们必须通过添加步骤“执行 sonarqube 扫描仪”来设置

enter image description here

任何人都可以帮助我们了解如何在 jenkins 管道作业中设置 Sonarqube 属性,否则我们可以在 Jnekins 的 Maven 或自由式作业类型中指定(如上面的快照所示)。 谢谢。

现在我已经更改了 Jenkins Pipeline Job 配置的 Groovy 脚本 - enter image description here

现在我收到错误 -

enter image description here

有人可以帮我解决上述问题吗?

最佳答案

在我的例子中,配置文件始终位于应用程序存储库中,然后从 jenkins 作业中调用 $WORKSPACE/sonar-project.properties

文件的内容是(示例):

# Required metadata
sonar.projectKey=<project-key>
sonar.projectName=<project-name>
sonar.projectVersion=<project-version>

# Comma-separated paths to directories with sources (required)
sonar.sources=src
sonar.exclusions=src/vendor/**/*

# Language
sonar.language=php

# Encoding of the source files
sonar.sourceEncoding=UTF-8

sonar.php.coverage.reportPath=src/coverage-clover.xml #change path to location of your test report
sonar.php.tests.reportPath=src/unitreport.xml  #change path to location of your test report

在 Jenkins/Global 工具配置中,您必须添加 Sonarqube 扫描仪,如下所示:

enter image description here

在管理 Jenkins/Configure 系统中,您必须添加 Sonarqube 服务器“redacted Sonarqube”,配置如下:

Sonarqube config example

在工作本身中,你有:

def scannerHome = tool 'azure-tools-sonarqube'  #This is the scanner you added

withSonarQubeEnv('redacted Sonarqube') {  #This is the server you added
  sh "${scannerHome}/bin/sonar-scanner"
}

关于Jenkins 管道作业构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45421333/

相关文章:

jenkins - 无法在 Windows 上的 Jenkins master 上设置工作区根目录

jenkins - 如何使用 Jenkins http-request 插件和管道在正文中发布 JSON 数据?

centos - Sonarqube - 服务 Sonar 在 centos 7 中不支持 chkconfig

java - 使用新名称将 Artifact 从 Jenkins 复制到另一台服务器

python - 如何使用 python 处理错误?

基于 Jenkins 角色的身份验证 - 用户缺少整体/读取权限

jenkins - 如何使用复制到从站插件

Jenkins - 将 Jenkins 制作的构建工件复制到其他位置或文件服务器

sonarqube - 启动 SonarQube 7.1 Web 服务器时出现问题

java - Java-这种使用java/lang/ProcessBuilder。<init>([Ljava/lang/String;)V可能容易受到命令注入(inject)(Sonar)的攻击