This repository contains a Jenkins pipeline for deploying a web application to an IIS server on Windows. The pipeline automates the process of checking out the code, restoring packages, building the application, and deploying it to IIS with maintenance mode handling.
- Automated Checkout: Pulls the latest code from the GitHub repository.
- Package Restoration: Restores .NET packages.
- Build Automation: Builds the application in Release mode.
- Deployment: Publishes the build to a specified directory.
- IIS Management: Stops and starts IIS sites and application pools.
- Maintenance Mode: Switches to a maintenance site during deployment.
- Email Notifications: Sends email notifications on build completion.
- Jenkins: Installed on a Windows server.
- .NET SDK: Installed on the Jenkins server.
- IIS: Installed and configured with the "working" and "maintenance" sites.
- Credentials: Configured in Jenkins for GitHub, IIS server, and email notifications.
- Checkout Stage: Checks out the code from the GitHub repository.
- Restore Packages: Restores the .NET packages required for the project.
- Build Stage: Builds the project in Release configuration.
- Deploy Stage: Publishes the build to a specified directory.
- Stop Site: Stops the IIS site and application pool for the working site.
- Start Maintenance Site: Starts the maintenance site and its application pool.
- Publish Stage: Copies the published build to the IIS server.
- Stop Maintenance Site: Stops the maintenance site and its application pool.
- Start Site: Starts the working site and its application pool.
GIT_ACCESS_TOKEN
: GitHub access token for cloning the repository.INSTANCE_CREDS
: Jenkins credentials ID for IIS server access (username and password).INSTANCE_HOST
: Jenkins credentials ID for the IIS server hostname.EMAIL_RECIPIENT
: Email address to receive build notifications.
-
Checkout Stage:
- Uses
GIT_ACCESS_TOKEN
to clone the repository. - Replace
your-username
andyour-repo
with your actual GitHub username and repository name.
- Uses
-
Restore Packages:
- Restores .NET packages from the project directory.
-
Build Stage:
- Builds the .NET project in Release configuration.
-
Deploy Stage:
- Publishes the .NET project to a specified directory.
-
Stop Site:
- Stops the IIS site and application pool for the "working" site to prepare for deployment.
-
Start Maintenance Site:
- Starts the "maintenance" site and its application pool to display maintenance information.
-
Publish Stage:
- Copies the published build files to the IIS server using network share credentials.
-
Stop Maintenance Site:
- Stops the "maintenance" site and its application pool after deployment is complete.
-
Start Site:
- Restarts the "working" site and its application pool to go live with the new deployment.
-
Clone the Repository:
git clone /~https://github.com/your-username/jenkins-iis-cicd-pipeline.git cd jenkins-iis-cicd-pipeline
-
Create a Jenkins Job:
- Open Jenkins and create a new Pipeline job.
- In the Pipeline section, configure it to use this repository.
- Set the script path to
Jenkinsfile
.
-
Configure Jenkins Credentials:
- Add credentials in Jenkins for
GIT_ACCESS_TOKEN
,INSTANCE_CREDS
,INSTANCE_HOST
, and email notifications.
- Add credentials in Jenkins for
-
Verify Configuration:
- Ensure that all environment variables and credentials are properly set.
- Test the pipeline by triggering a build to ensure that each stage executes as expected.
This project is licensed under the MIT License.