如何使用 sonarQube 分析不同阶段的构建和测试步骤?

问题描述

我的构建步骤和测试步骤在我的 Jenkins 管道中处于两个不同的阶段,但从 sonarQube documentation 来看,构建和测试命令似乎需要在同一代码块中。有什么方法可以使用 sonarQube 分析工具在不同的管道阶段进行构建和测试吗?我的 Jenkinsfile 中有以下结构

node {
    stage('checkout code from git') {
        cleanWs()
        checkout scm
    }
    
    stage('Build') {
    def buildVersion = "1.0.0.1"
        withSonarQubeEnv('mySonarQubeScanner') 
        {
            sh "dotnet-sonarscanner begin /k:'TestProject' /d:sonar.cs.vscoveragexml.reportsPaths='unit_tests.xml'"     
            
            sh "dotnet restore testProject/testProject.csproj -p:Version=$buildVersion -p:FiLeversion=$buildVersion -p:AssemblyVersion=$buildVersion"
            sh "dotnet publish testProject/testProject.csproj --output bin/application/testApp --configuration Release -p:Version=$buildVersion -p:FiLeversion=$buildVersion -p:AssemblyVersion=$buildVersion"
        
            sh "dotnet-sonarscanner end"
        }
    }
    
    stage('test) {
        sh "dotnet restore testProject.Test/testProject.Test.csproj"
        sh "dotnet test --configuration Release --logger \"trx;LogFileName=unit_tests.xml\" testProject.Test"
    }
}

如前所述,我希望保持管道的相同结构,以便能够查看测试覆盖率报告,但我现在不知道如何实现这一点,因为我有两个阶段。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)