Getting Started with Jenkins CI/CD for .NET Projects
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
- Install required plugins:
Jenkins → Manage Jenkins → Manage Plugins → Available - Git plugin - MSBuild plugin - Pipeline - Azure Credentials (if deploying to Azure) - Create a new Pipeline job and configure the SCM:
- Configure environment variables for secure secrets (e.g.,
AZURE_CLIENT_ID,AZURE_CLIENT_SECRET) via Credentials and reference them in the pipeline. - Run the pipeline and verify that all stages succeed.
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/**'
}
}
}
}
Tips & Tricks
- Use
dotnet cleanto ensure a fresh build. - Parallelize unit test execution with
dotnet test --parallel. - Cache NuGet packages on the agent to speed up builds.
Comments (3)
dotnet-sonarscannerfor static analysis.