Jenkins CI/CD for ASP.NET Core + Angular App Deployment

Leave a Comment

Applications built using Angular for the frontend and ASP.NET Core for the backend are frequently deployed by hand, requiring file copies, Visual Studio publishing, IIS restarts, and other steps. Manual deployment becomes dangerous as your team increases, although it works well for small projects. One minor error could overwrite settings or result in downtime.

Jenkins' Continuous Integration and Continuous Deployment (CI/CD) technology can help with it.
Every time you push code, it swiftly and safely builds, tests, and deploys your project. I'll walk you through the process of utilizing the Jenkins pipeline to deploy a full-stack application (Angular + ASP.NET Core) on a Windows server (IIS) in this post.

Requirements

Before we start, make sure you have:

  • Installed Jenkins (Windows or Linux)

  • Installed .NET SDK (e.g. .NET 8.0) on the Jenkins server

  • Installed Node.js and Angular CLI

  • Installed Git (for source code checkout)

  • Access to your IIS server for deployment

Project Structure

Below is a common folder structure we’ll work with:

HFLDemoApp/
 ├── WebAPI/             # ASP.NET Core Backend
 ├── ClientApp/          # Angular Frontend
 ├── Jenkinsfile         # Jenkins pipeline script
 ├── deploy.ps1          # PowerShell script for IIS deployment

Step 1. Create a Jenkins Pipeline Job

  1. Open Jenkins Dashboard → New Item → Pipeline

  2. Give it a name, e.g., RajeshDemoApp-CI-CD

  3. Under Pipeline definition, select Pipeline script from SCM

  4. Choose Git, and provide your repo URL.

  5. Jenkins will now read the Jenkinsfile from your repository.

Step 2. Jenkinsfile Configuration

Here’s a simple Jenkinsfile example for our project:

pipeline {
    agent any

    stages {
        stage('Checkout Code') {
            steps {
                git branch: 'main', url: 'https://github.com/your-repo'
            }
        }

        stage('Build Angular') {
            steps {
                dir('ClientApp') {
                    bat 'npm install'
                    bat 'ng build --configuration production'
                }
            }
        }

        stage('Build .NET Core') {
            steps {
                dir('WebAPI') {
                    bat 'dotnet restore'
                    bat 'dotnet publish -c Release -r win-x64 -o ../publish'
                }
            }
        }

        stage('Deploy to IIS') {
            steps {
                bat 'powershell .\\deploy.ps1'
            }
        }
    }
}

Note:
If you’re using Linux agents, replace bat with sh.

Step 3. Create PowerShell Script for Deployment

Let’s create a PowerShell file named deploy.ps1 at the root of your repo.

This script will:

  • Stop IIS site

  • Backup old files

  • Copy new build files

  • Restart IIS site

Write-Host "Starting deployment..."

$source = "C:\Jenkins\workspace\MyApp-CI-CD\publish"
$destination = "C:\inetpub\wwwroot\RajeshDemoApp"
$backup = "C:\Backup\MyApp_" + (Get-Date -Format "yyyyMMdd_HHmmss")

# Stop IIS
iisreset /stop

# Backup existing site
if (Test-Path $destination) {
    Copy-Item $destination $backup -Recurse
    Write-Host "Backup created at $backup"
}

# Copy new files
Copy-Item $source\* $destination -Recurse -Force

# Start IIS
iisreset /start

Write-Host "Deployment completed successfully."

Step 4. Handle Configuration Files

We usually have environment-specific files like:

  • appsettings.Production.json

  • environment.prod.ts

You can use a small PowerShell snippet to replace these files based on environment before publishing.

Example:

Copy-Item ".\Configs\Production\appsettings.json" ".\WebAPI\appsettings.json" -Force

Step 5. Run the Pipeline

  1. Commit and push your code (including Jenkinsfile).

  2. Go to Jenkins → click Build Now.

  3. Jenkins will run each stage — build Angular, build .NET, deploy to IIS.

Step 6. Troubleshooting Tips

If deployment fails:

  • Check Jenkins console logs (very helpful).

  • Make sure IIS user has write permission to your deployment folder.

  • Ensure Node.js, Angular CLI, and .NET SDK paths are configured in Jenkins.

Step 7. Benefits of Using CI/CD

After setting this up once, your deployments become:

  • Automatic – no manual file copying

  • Consistent – same steps every time

  • Fast – 1-click deployment from Jenkins

  • Safe – automatic backup and rollback

Conclusion

By combining Jenkins, ASP.NET Core, and Angular, we can automate our entire deployment process.

No more “it works on my machine” issues — your build, test, and deployment happen exactly the same way every time.

Windows Hosting Recommendation

HostForLIFE receives Spotlight standing advantage award for providing recommended, cheap and fast ecommerce Hosting including the latest Magento. From the leading technology company, Microsoft. All the servers are equipped with the newest Windows Server 2022 R2, SQL Server 2022, ASP.NET Core 10.0 , ASP.NET MVC, Silverlight 5, WebMatrix and Visual Studio Lightswitch. Security and performance are at the core of their Magento hosting operations to confirm every website and/or application hosted on their servers is highly secured and performs at optimum level. mutually of the European ASP.NET hosting suppliers, HostForLIFE guarantees 99.9% uptime and fast loading speed. From €3.49/month , HostForLIFE provides you with unlimited disk space, unlimited domains, unlimited bandwidth,etc, for your website hosting needs.
 
https://hostforlifeasp.net/
Next PostNewer Post Previous PostOlder Post Home

0 comments:

Post a Comment