Q:

How to automatically deploy asp.net core application to ec2 instance using jenkins?

I have hosted an ASP.NET Core web application on an EC2 instance using Nginx. The EC2 isntance is running on Ubuntu Server 16.04 LTS machine.
I am developing the code in windows machine and publishing the code. Then copying the files into the EC2 instance using WinSCP. The web application is running nicely and i can hit the application using postman or browser.
Now, i have decided to use jenkins for CI/CD. I have installed jenkins in the same ec2 server where my web application running. Jenkins is running in port 8080 and my web application is running in port 80. I have configured jenkins with my bitbucket repository by following this link.
Now, my jenkins server is up and running. If i commit anything in the bitbucket repository, jenkins server automatically triggers a build.
Previously, i have published the code using below command:
dotnet publish -o my-sample-site

And then copied the files from my-sample-site directory to the directory in EC2 instance. Now, i want to automatically build the asp.net core web source codes and publish the codes to the folder where my web application is running. I may have to restart the service also after changing the codes.
What should i include in the jenkins build step so that whenever bitbucket repository changes triggers build in jenkins, it will build the asp.net core source codes and then publish the codes in the directory of the EC2 instance where my web application is running.
How should i do this automatically? Any reference please. Thanks in advance.

A:

I have set up CI/CD server using Jenkins connected to a Bitbucket repository for an ASP.NET Core Web API running in an EC2 instance. Anyone can check my article here.

