首頁 Use Jenkins Run CI/CD
文章
Cancel

Use Jenkins Run CI/CD

安裝jenkins

1.下載jenkins

https://www.jenkins.io/

2.下載Java環境 (環境需求)

https://www.oracle.com/java/technologies/downloads/#jdk17-windows

MSBuild 建置

安裝jenkins的MSBuild插件

Desktop View Desktop View

設定MSBuild路徑

Desktop View Desktop View Desktop View

取得本機MSBuild.exe路徑

VS 2022 MSBuild路徑

1
C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin

[本地專案] 重建

建立Job,並設定VS專案路徑

Desktop View Desktop View Desktop View

[本地專案] 單元測試

簡單Report

Jenkins安裝NUnit plugin Desktop View

下載NUnit Console

https://nunit.org/download/

確認有安裝成功

Desktop View

Jenkins建立Job

選擇建立「執行 Windows 批次指令」

Desktop View

1
"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" "C:\Users\User\source\repos\ConsoleApp1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" -result =TestResult.xml;format=nunit2 

執行後,可以看到單元測試的報表

Desktop View

更多Report

Jenkins安裝NUnit plugin Desktop View Jenkins安裝HTML Publisher plugin Desktop View Jenkins安裝Cobertura Plugin Desktop View

下載 NUnit Console :https://nunit.org/download/
下載 OpenCover :https://github.com/OpenCover/opencover/releases
下載 ReportGenerator :https://github.com/danielpalme/ReportGenerator/releases
下載 OpenCoverToCoberturaConverter :https://www.nuget.org/packages/OpenCoverToCoberturaConverter 備註 :上述都直接載ZIP解壓縮以便能快速找到exe位置為主
Desktop View

1
2
3
"C:\Users\User\Downloads\JenkinsTool\opencover\OpenCover.Console.exe" -register:user -target:"C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" -targetargs:"C:\Users\User\source\repos\ConsoleApp1\UnitTestProject1\bin\Debug\UnitTestProject1.dll" -filter:"+[*]*" -output:Coverage.xml
"C:\Users\User\Downloads\JenkinsTool\D\net47\ReportGenerator.exe" -reports:Coverage.xml -targetDir:CodeCoverageHTML
"C:\Users\User\Downloads\JenkinsTool\opencovertocoberturaconverter\tools\OpenCoverToCoberturaConverter.exe" -input:Coverage.xml -output:Cobertura.xml -sources:C:\Users\User\source\repos\ConsoleApp1

CI 持續整合

安裝插件 Warnings Next Generation

備註

Server重啟指令-非強制重啟

1
(jenkins_url)/safeRestart

Server重啟指令-強制重啟

1
(jenkins_url)/restart
本文由作者按照 CC BY 4.0 進行授權