How to publish ASP.NET Core application by using Jenkins
Tags: aspnetcore, jenkins, devops, iis
Published: 2020-01-24 12:55:16

This article was originally published at:  [https://www.ahmetkucukoglu.com/en/how-to-publish-asp-net-core-application-by-using-jenkins/](https://www.ahmetkucukoglu.com/en/how-to-publish-asp-net-core-application-by-using-jenkins/)

In this article, i will describe how to publish ASP.NET Core application by using Jenkins. Since the subject of the article is about preparing pipeline, you can benefit the link below for the installation of Jenkins.

[How to Install Jenkins on Windows | BlazeMeter](https://www.blazemeter.com/blog/how-to-install-jenkins-on-windows)

Because the target machine on which we will make deployment in our scenerio and the machine in which Jenkins has been installed will be different , we need to arrange a dedicated server for Jenkins. The reason is that the Jobs could deplete your resources while they are working.

The pipeline is made of the following 4 steps.

**Checkout:** Pull the source code from the Github  
**Build:** Build the source code  
**Deploy:** Deployment to the target machine

Before preparing the pipeline, you need to fulfil the requirements below.

**1. The installation of the Git**  
In order to get the checkout done, the Git need to be installed in the Jenkins machine. You can install the Git by using the address below.

[Git - Downloading Package](https://git-scm.com/download/win)

**2. The installation of NET Core SDK**  
To make the build, NET Core SDK need to be installed in the Jenkins machine. By using the address below, you can install the relevant SDK according to the version in your application.

[Download .NET (Linux, macOS, and Windows)](https://dotnet.microsoft.com/download)

**3. The installation of the MsDeploy in the Jenkins machine**  
To deployment, the msdeploy need to be installed in the Jenkins machine. For this, you can download the relevant installment from the address below.

[Web Deploy 3.6 : The Official Microsoft IIS Site](https://www.iis.net/downloads/microsoft/web-deploy)

**4. The introduction of the trusted machine ** 
If the Jenkins machine and the target machine are not in the same domain, the deployment from the Jenkins machine to the target machine can't be done. There will be an error like below.

To solve the error, you need to indicate to Jenkins that the target machine is trusted. For this, you can apply the command line below in the Powershell.

```
winrm set winrm/config/client '@{TrustedHosts="0.0.0.0"}'
```

**5. The installation of the Web Management Service**  
To deployment remotely to the target machine, Web Management Service need to be installed and to be running in the IIS. Open the IIS to check whether the service has been installed. Choose your server from the connections window on the left. Check the Management Service module on the right section below the Management tab.

![IIS - Management Service ](https://www.ahmetkucukoglu.com/wp-content/uploads/2019/10/01-1024x603.png)

If the module does not appear, you can install the Management Tools from the Windows features.

**6. The activation of the Web Management Service**  
The module need to be in a running state. You can activate the option "Enable Remote Connections" by double clicking the module, and make start.

![IIS - Management Service 2](https://www.ahmetkucukoglu.com/wp-content/uploads/2019/10/02-1024x602.png)

**7. The installation of the Msdeploy in the target machine**  
The MsDeploy need to be installed in the target machine. For this, you can download the relevant installment from the address below, and install it.

[Web Deploy 3.6 : The Official Microsoft IIS Site](https://www.iis.net/downloads/microsoft/web-deploy)

Within the process of installation, you need to activate the "IIS Deployment Handler" feature by choosing the "Custom" option.

![MsDeploy](https://www.ahmetkucukoglu.com/wp-content/uploads/2019/10/03.png)

Open the IIS to check whether the service has been installed successfully. Choose your server from the connections window on the left. Check the Management Service Delegation module which is on the right and below the Management tab.

![IIS Management Service Delegation](https://www.ahmetkucukoglu.com/wp-content/uploads/2019/10/04-1024x602.png)

Everything is ready. Right now we can prepare the pipeline in the Jenkins.

----------

Open Jenkins, follow the way "New Item > Pipeline" and create "job".

![Jenkins - New Item](https://www.ahmetkucukoglu.com/wp-content/uploads/2019/10/05.png)

Paste the script below to the Pipeline section.

{% gist https://gist.github.com/ahmetkucukoglu/d7dc7283ddb79677386b1e4cef904e8c %}

We are done. From now on you can make "Build Now". Good luck…