声纳相当新。到目前为止,我能够在 jenkins 中配置我的 sonarqube 服务器并使用以下代码运行 Maven 应用程序。
withSonarQubeEnv('sonarserver') {
sh 'mvn clean package sonar:sonar'
}
这会成功运行并进行分析以及 Maven 构建并生成一个 War 文件。我还可以在 sonarqube 页面中看到分析
现在我正在尝试对 .net core 应用程序做同样的事情。我按照这个link
安装了声纳扫描仪第一步成功运行,我得到:
dotnet tool install --global dotnet-sonarscanner
Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.
You can invoke the tool using the following command: dotnet-sonarscanner
所以我接下来创建了以下代码:
withSonarQubeEnv('sonarserver') {
sh '''
dotnet-sonarscanner begin /k:"proyject-key" //key was generated in sonarqube x new proj.
dotnet build solution.sln
dotnet-sonarscanner end
'''
但现在我得到:
+ dotnet-sonarscanner begin /k:project-key
/var/lib/jenkins/workspace/sonar-test-dotnet@tmp/durable-00ff368b/script.sh: 3: /var/lib/jenkins/workspace/sonar-test-dotnet@tmp/durable-00ff368b/script.sh: dotnet-sonarscanner: not found
[Pipeline] }
WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeed?
根据您提到的文档,执行的命令应该是:
dotnet sonarscanner begin /k:"proyject-key" //key was generated in sonarqube x new proj.
dotnet build solution.sln
dotnet sonarscanner end
而不是:
dotnet-sonarscanner begin /k:"proyject-key" //key was generated in sonarqube x new proj.
dotnet build solution.sln
dotnet-sonarscanner end
将
dotnet-sonarscanner
替换为 dotnet sonarscanner
。
这个阶段对我来说很适合。
pipeline {
agent any
environment {
PROYECT_FOLDER = 'xxx'
PROYECT_NAME = 'xxx'
PROYECT_TEST_FOLDER = 'xxt'
PROYECT_TEST_NAME = 'Mxxx'
SONAR_KEY_PROYECT = 'xx'
SONAR_URL = 'xxx'
SONAR_LOGIN = 'xx' //Key get from sonar
}
stages {
......
stage('Build + SonarQube analysis') {
environment {
MSBUILD_SQ_SCANNER_HOME = tool name: 'SonaScanner.NetCore'
}
steps {
withSonarQubeEnv('sonarqube') {
sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll begin /k:'${SONAR_KEY_PROYECT}' /d:sonar.host.url=${SONAR_URL} /d:sonar.login=${SONAR_LOGIN} "
sh "dotnet build ${PROYECT_FOLDER}/${PROYECT_NAME} --configuration Release --no-restore"
sh "dotnet ${MSBUILD_SQ_SCANNER_HOME}/SonarScanner.MSBuild.dll end /d:sonar.login=${SONAR_LOGIN}}"
}
}
}