環(huán)境準備
- 系統(tǒng)
linux- 環(huán)境
dotnet core
jenkins:自動化部署
.NET Core 2.2 SDK:用來編譯項目
.NET Core 2.2 Runtime:The runtime includes everything you need to run .NET Core applications. The runtime is also included in the SDK
項目以linux服務的方式使用Kestrel發(fā)布,再配上nginx,可以反向代理的方式訪問項目
jenkins相關(guān)配置:
有shell命令可以看出建丧,再次以systemd服務形式發(fā)布的ASP.NET Core項目
在/lib/systemd/system下添加 mcl.service
vim /lib/systemd/system/mcl.service
wq!保存退出
運行服務檢查服務是否能運行
sudo systemctl start mcl.service
sudo systemctl status mcl.service
fcj@ubuntu:~$ sudo systemctl status mcl.service
● mcl.service - run MclServer on ubuntu
Loaded: loaded (/lib/systemd/system/mcl.service; disabled; vendor preset: ena
Active: active (running) since Sat 2019-08-31 05:08:22 CST; 1h 16min ago
Main PID: 5640 (dotnet)
Tasks: 17 (limit: 3492)
CGroup: /system.slice/mcl.service
└─5640 /usr/bin/dotnet /var/lib/jenkins/workspace/MclServerCore/Integ
8月 31 05:08:22 ubuntu systemd[1]: Started run MclServer on ubuntu.
8月 31 05:08:24 ubuntu dotnet[5640]: Hosting environment: Production
8月 31 05:08:24 ubuntu dotnet[5640]: Content root path: /var/lib/jenkins/workspa
8月 31 05:08:24 ubuntu dotnet[5640]: Now listening on: http://[::]:8020
8月 31 05:08:24 ubuntu dotnet[5640]: Application started. Press Ctrl+C to shut d
服務正常后劲妙,關(guān)閉服務sudo systemctl stop mcl.service
迎献,保存jenkins的配置,構(gòu)建項目:
控制提輸出報錯
+ sudo systemctl stop mcl.service
sudo: 沒有終端存在,且未指定 askpass 程序
Build step 'Execute shell' marked build as failure
Finished: FAILURE
可見jenkins的shell腳本操作systemd服務出錯了
fcj@server:~$ sudo visudo
對sudo 設置成免密形式
再次執(zhí)行jenkins構(gòu)建:
在瀏覽器訪問項目發(fā)布的頁面: