```html Jenkins CI/CD for .NET – MSDN Community

Getting Started with Jenkins CI/CD for .NET Projects

Posted by Jane Doe • Sep 10, 2025 • .NET CI/CD

Continuous Integration and Continuous Deployment (CI/CD) are essential for modern .NET development. Jenkins, a popular open‑source automation server, can be tailored to build, test, and deploy .NET applications across Windows, Linux, and macOS agents.

Prerequisites

  • Jenkins server (latest LTS)
  • .NET SDK (6.0 or later) installed on the build agent
  • Git repository with your solution

Step‑by‑Step Setup

  1. Install required plugins:
    Jenkins → Manage Jenkins → Manage Plugins → Available
    - Git plugin
    - MSBuild plugin
    - Pipeline
    - Azure Credentials (if deploying to Azure)
  2. Create a new Pipeline job and configure the SCM:
  3. pipeline {
        agent any
        stages {
            stage('Checkout') {
                steps {
                    git url: 'https://github.com/yourorg/yourproject.git', branch: 'main'
                }
            }
            stage('Restore') {
                steps {
                    bat 'dotnet restore'
                }
            }
            stage('Build') {
                steps {
                    bat 'dotnet build --configuration Release'
                }
            }
            stage('Test') {
                steps {
                    bat 'dotnet test --no-build --configuration Release'
                }
            }
            stage('Publish') {
                steps {
                    bat 'dotnet publish -c Release -o ./publish'
                }
            }
            stage('Deploy') {
                steps {
                    // Example: Deploy to Azure App Service
                    azureWebAppPublish credentialsId: 'azure-cred', resourceGroup: 'RG', appName: 'myapp', 
                                      srcPath: 'publish/**'
                }
            }
        }
    }
  4. Configure environment variables for secure secrets (e.g., AZURE_CLIENT_ID, AZURE_CLIENT_SECRET) via Credentials and reference them in the pipeline.
  5. Run the pipeline and verify that all stages succeed.

Tips & Tricks

  • Use dotnet clean to ensure a fresh build.
  • Parallelize unit test execution with dotnet test --parallel.
  • Cache NuGet packages on the agent to speed up builds.

Comments (3)

Mike L.
Sep 9, 2025 at 14:32
Great starter guide! I’d also recommend using the dotnet-sonarscanner for static analysis.
Sofia R.
Sep 9, 2025 at 10:07
Can this pipeline be used for .NET 8 preview builds? Any tweaks needed?
Alex K.
Sep 8, 2025 at 18:45
Remember to enable the “Allow script to be run” policy on Windows agents.
```