[Jenkins]Automated deploy

這篇來看看如何透過Jenkins進行automated deploy to environment of integration Test

上一篇,我已經透過Jenkins進行pull code,build and run test case,

整個流程大致如下圖框選部分

這篇我將繼續補上automated deploy(上圖未框選部分)。

@install Nginx

sudo yum -y install epel-release # add Nginx Repository
sudo yum -y install nginx
vi /etc/nginx/nginx.conf

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

我將透過Nginx進行反向代理,來handle所有http requests送至kestrel(cross-platform web server)處理,

jenkins將自動佈署NetCore Application和啟動Kestrel web server (nginx service需先啟動)。

Note:

SELinux造成connect() to localhost:5000 failed (13: Permission denied),

可透過下面command確認SELinux是否為兇手

sudo cat /var/log/audit/audit.log | grep nginx | grep denied

可以看到httpd並沒有開啟,我們可以透過下面command來啟用。

setsebool -P httpd_can_network_connect 1
sudo groupadd appadmin
sudo usermod -a -G appadmin Jenkins
groups Jenkins #check

Note:我習慣建立一個appgroup,然後將jenkins加入該group,這樣處理檔案權限會比較方便。

 

@create a new job

其他設定和上一篇大同小異,這裡我將不設定觸發程序(有需要時自行手動建立),

build scripts也大同小異,我就不多加說明。

 

Jenkins執行結果

@確認結果

個人windows開發環境,Version沒有任何後綴字串。

 

Integration Test(on CentOS 7)

透過nginx reverse proxy server

透過kestrel web server

可看到Version都多了後綴IntegrationTest字串,可更加提醒我們目前所使用環境。

 

參考

Kestrel web server implementation in ASP.NET Core

Additions to the csproj format for .NET Core

Host ASP.NET Core on Linux with Nginx

Displaying and Setting Current ASPNET Assembly Version

Asp.Net Core Auto Deploy (AWS,Jenkins, Docker, Nginx)

Microsoft.NET.DefaultAssemblyInfo.targets

Unable to use <Version> in .csproj with --version-suffix

ASP.NET Core Web Servers: Kestrel vs IIS Feature Comparison and Why You Need Both

ASP.NET Core 2 系列 - Kestrel Web Server

Publishing and running your ASP.NET Core project on Linux