簡體   English   中英

Jenkins and SonarQube for Pipeline Gating without using the SonarQube Jenkins Plugin in bash

[英]Jenkins and SonarQube for Pipeline Gating without using the SonarQube Jenkins Plugin in bash

We have a build that runs SonarQube from Jenkins using a bash script, and we want to get the results of the tests back in the Jenkins pipeline so we can prevent merges on fail. We are using v2 of Jenkins, but it is an old version that doesn't support the SonarQube Jenkins plugin, and upgrading Jenkins isn't something we can accomplish in our sprint.

有沒有辦法用我們所擁有的來獲得結果來控制我們的管道? 目前,這就是我們在 OpenShift 中從 Jenkins 運行 SonarQube 的方式。

dotnet build
~/.dotnet/tools/coverlet "./bin/Debug/netcoreapp3.1/AppTests.dll" --target "dotnet" --targetargs 'test . --no-build --logger "trx;LogFileName=TestResults.trx" --logger "xunit;LogFileName=TestResults.xml" --results-directory ../BuildReports/UnitTests' -f opencover -o ./BuildReports/Coverage/coverage
dotnet build-server shutdown

~/.dotnet/tools/dotnet-sonarscanner begin /k:${APP_NAME} /n:${APP_NAME} /d:sonar.host.url=${SONAR_URL} /d:sonar.cs.opencover.reportsPaths="./BuildReports/Coverage/coverage.opencover.xml" /d:sonar.exclusions="**/Migrations/*" /d:sonar.coverage.exclusions="**Tests*.cs","**/Migrations/*","**/Program.cs" /d:sonar.cpd.exclusions="**/Migrations/*" /d:sonar.cs.vstest.reportsPaths="./BuildReports/UnitTests/TestResults.trx" /d:sonar.cs.nunit.reportsPaths="./BuildReports/UnitTests/TestResults.xml"
dotnet build -v n

~/.dotnet/tools/dotnet-sonarscanner end
dotnet build-server shutdown

在 SonarQube 服務器上安裝 Build Breaker 插件。 並為您正在掃描的項目啟用它——在 SonarQube 服務器上的項目設置中執行此 go。 您可能需要服務器級別和項目級別的管理權限才能執行此操作。
現在,Sonar Scanner 將在進行代碼分析后檢查質量門狀態。 如果質量門失敗,掃描器返回一個非零狀態代碼,可用於將構建標記為“失敗”。
https://github.com/adnovum/sonar-build-breaker#sonarqube-build-breaker-plugin

In case you don't have control over what gets installed on the SonarQube server, then you may write a bash script to use the curl command to hit web API of your SonarQube server to first find if the analysis report has been processed by the SonarQube服務器,然后代碼分析的質量門狀態剛剛結束。
有關 web API 的文檔,請參閱http://<sonarqube-server-host>/web_api

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM