无法在Jenkins上执行SonarScanner for .NET项目,因为“dotnet-sonarscanner:未找到”

tf7tbtn2  于 2023-10-17  发布在  Jenkins
关注(0)|答案(2)|浏览(184)

新的声纳。到目前为止,我能够在jenkins中配置我的sonarqube服务器,并使用以下代码运行maven应用程序。

withSonarQubeEnv('sonarserver') {

     sh 'mvn clean package sonar:sonar'
             
    }

这将成功运行,并执行分析和maven构建,并生成一个war文件。此外,我可以在sonarqube页面中看到分析
现在我正试图为.net核心应用程序做同样的事情。我安装了sonarscanner如下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?
guz6ccqo

guz6ccqo1#

根据你提到的文档,执行的命令应该是:

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

kdfy810k

kdfy810k2#

这个阶段为我工作。

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}}"
             }
         }
     }

相关问题