2017-07-20 60 views
0

有沒有辦法突破的時候聲納質量門與waitForQualityGate()方法失敗,聲納掃描儀沿着MSBuild的詹金斯建?我找不到任何相同的文檔。我所能找到的只是使用waitForQualityGate()和Sonar掃描儀,但不推薦使用通用聲納掃描儀進行MSbuild項目。waitForQualityGate()與聲納掃描儀的MSBuild

下面提到的鏈接並沒有提及使用waitForQualityGate和MSBuild。 https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Jenkins#AnalyzingwithSonarQubeScannerforJenkins-AnalyzinginaJenkinspipeline

該文件談到了聲納掃描儀,但我指的是完全不同的掃描儀MSbuild的聲納掃描儀。我使用這種掃描儀的方式如下所示。

void beginSonarMSBuild(String VERSION){ 
    stage('Begin Sonar Analysis') { 
    def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
    withSonarQubeEnv('civil sonar') { 
    bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe begin /k:mcdc 
    /n:mc-design-converter /v:${VERSION}.$BUILD_NUMBER /d:sonar.sourceEncoding=UTF-8 
    } 
    } 
} 
void build(){ 
    stage ('Build'){ 
    bat "Nuget restore SOMEHTING.sln" 
    bat "MSBuild.exe SOMETHING.csproj " 
    } 
} 
void endSonarMSBuild(){ 
    stage ('Complete Sonar Analysis'){ 
    def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
    bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end" 
} 
} 

現在,當我使用waitforqualitygate()beginSonarMSBuild(String VERSION)如下圖所示:

void beginSonarMSBuild(String VERSION){ 
    stage('Begin Sonar Analysis') { 
    def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
    withSonarQubeEnv('civil sonar') { 
    bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe begin /k:mcdc 
    /n:mc-design-converter /v:${VERSION}.$BUILD_NUMBER /d:sonar.sourceEncoding=UTF-8 
    } 
    } 
    stage("Quality Gate"){ 
     timeout(time: 1, unit: 'MINUTES') { 
     def qg = waitForQualityGate() 
     if (qg.status != 'OK') { 
      error "Pipeline aborted due to quality gate failure: ${qg.status}" 
     } 
    } 
} 

void build(){ 
scripts here... 
} 
void endSonarMSBuild(){ 
scripts here... 
} 

我得到這個錯誤味精java.lang.IllegalStateException: Unable to get SonarQube task id and/or server name. Please use the 'withSonarQubeEnv' wrapper to run your analysis.

我也得到了同樣的錯誤,當我使用waitForQualityGate()endSonarMSBuild()步如圖所示下面。

void beginSonarMSBuild(String VERSION){ 
stage('Begin Sonar Analysis') { 
scripts here... 
} 

void build(){ 
scripts here... 
} 

void endSonarMSBuild(){ 
stage ('Complete Sonar Analysis'){ 
def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end" 
} 
stage("Quality Gate"){ 
    timeout(time: 1, unit: 'MINUTES') { 
    def qg = waitForQualityGate() 
    if (qg.status != 'OK') { 
     error "Pipeline aborted due to quality gate failure: ${qg.status}" 
    } 
    } 
    } 
} 

所以我是這個問題,並聲納掃描儀的MSBuild甚至支持waitForQualityGate(),如果是的話,那麼如何使用相同的?

+0

我真的不明白你的問題。該但是當代碼沒有通過聲納質量門時,buil會自動失敗,並且waitForQualityGate()是正確的方法 – arifCee

+0

但是,在何處使用waitForQualityGate()?作爲「SonarQube.Scanner.MSBuild.exe開始」或「SonarQube .Scanner.MSBuild.exe結束'步驟?請注意''聲納掃描儀'是不同於'聲吶掃描儀的MSbuild' –

回答

1

在文檔中,該示例是使用Maven掃描儀制作的,但只要您將其包裝在withSonarQubeEnv步驟中,它就可以在任何掃描儀上正常工作。

對於掃描儀的MSBuild,它包裹的結束步驟(但包裹開始一步也是一個好主意,會自動傳遞憑據是很重要的。

void beginSonarMSBuild(String VERSION) { 
    stage('Begin SonarQube Analysis') { 
     def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
     withSonarQubeEnv('civil sonar') { 
      bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe begin /k:mcdc 
    /n:mc-design-converter /v:${VERSION}.$BUILD_NUMBER /d:sonar.sourceEncoding=UTF-8 
     } 
    } 
} 
void build() { 
    stage ('Build') { 
     bat "Nuget restore SOMEHTING.sln" 
     bat "MSBuild.exe SOMETHING.csproj" 
    } 
} 
void endSonarMSBuild() { 
    stage ('Complete SonarQube Analysis') { 
     withSonarQubeEnv('civil sonar') { 
      def MSBuildScannerHome = tool 'sonar-scanner-msbuild-3.0.0.629'; 
      bat "${MSBuildScannerHome}\\SonarQube.Scanner.MSBuild.exe end" 
     } // Will collect task id 
    } 
    stage("Quality Gate"){ 
     timeout(time: 1, unit: 'MINUTES') { 
      def qg = waitForQualityGate() 
      if (qg.status != 'OK') { 
       error "Pipeline aborted due to quality gate failure: ${qg.status}" 
      } 
     } 
    } 
} 
+0

我已更新我的問題,以便它更清楚。我的問題是特定於聲吶掃描儀MSBuild 。 –

+0

用'withSonarQubeEnv'包裝結束步驟非常重要。我用一個例子更新了我的答案。 –

+0

感謝您的幫助@Julien H.工作。 –