Deploy .NET 8 App on Ubuntu via Jenkins
Start with installing .NET 8 SDK
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
Check dotnet version with:
dotnet --version
System Service
Create service file for .NET application
sudo nano /etc/systemd/system/SERVICE_NAME.service
Example service file below replace SERVICE_NAME as desired:
[Unit]
Description=SERVICE_NAME API
[Service]
WorkingDirectory=/var/www/SERVICE_NAME
ExecStart=/usr/bin/dotnet /var/www/SERVICE_NAME/SERVICE_NAME.dll
Restart=always
# Restart service after 10 seconds if the dotnet service crashes:
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=SERVICE_NAME-app
User=www-data
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
[Install]
WantedBy=multi-user.target
Run service with:
sudo systemctl enable
SERVICE_NAME
.service
sudo systemctl startSERVICE_NAME
.service
Create Jenkins Project
Click New Item and create a freestyle project on Jenkins dashboard.
In Source Code Management choose Git and enter details.
Select GitHub hook trigger for GITScm polling from Build Triggers.
Click Add Build Step > Execute Shell and write shell details as shown in below.
-p:RunAnalyzers=false is added on this example because my service is getting built very slow.
Save changes and move to the next step.
Enable webhook on your GitHub repository settings. Use your {Jenkins IP}:8080
After you push a new commit on selected branch, Jenkins should build your .NET application and publish it.
Check your service status with:
sudo systemctl start
SERVICE_NAME
.service
If there is any problems you can check your service logs with:
sudo journalctl -fuSERVICE_NAME
.service
Bonus: How to solve write permission error on ubuntu for .NET service
Comments
Comments are closed