AN APPROACH TO *NIX-HOSTED JENKINS SERVER TO WINDOWS SERVER CONTINUOUS DEPLOYMENT

Introduction??

This document outlines the setup of an automated deployment pipeline that transfers web applications from Azure DevOps to a Windows IIS server using Jenkins and PowerShell. It is crucial to understand that this design considers the limitation of not being able to add Windows as a worker node in Jenkins.?

The pipeline orchestrates the build process on an AWS EC2 Ubuntu instance running Jenkins, while deployment operations are executed on an AWS EC2 Windows Server 2022 Datacenter instance hosting IIS. Secure file transfer is facilitated through SMB shares, and notifications are sent to Slack or MS Teams via webhooks as shown in diagram below.??

?

Infrastructure Details & Testing?

Systems Requirements:?

  • Jenkins Server: Hosted on AWS EC2 Ubuntu instance.?
  • IIS Server: Deployed on AWS EC2 instance.?
  • AWS Security Groups: Ports 80 (HTTP) and 443 (HTTPS) opened to allow communication from the IIS server.?
  • Source Code Repository: Azure DevOps hosts the source code for the web application.?
  • Authentication Mechanisms: Secure authentication methods used for communication among Jenkins, Azure DevOps, and the Windows IIS server.?

Testing:?

The deployment pipeline has been thoroughly tested with the following infrastructure:?

  • Ubuntu Version: 24.04 LTS (GNU/Linux 6.8.0-1008-aws x86_64)?
  • Jenkins Version: 2.56.x?
  • Windows Server: 2022 Datacenter?

High-Level Design (HLD)?

Components:?

  • Azure DevOps: Source code repository for the web application.?

  • Jenkins: Automation server managing the CI/CD pipeline.?
  • Ubuntu Server: AWS EC2 Ubuntu instance hosting Jenkins.?
  • Windows IIS Server: AWS EC2 Windows Server 2022 Datacenter instance hosting the web application.?
  • SMB Shares: Used for secure file transfer between Jenkins and the IIS server.?
  • PowerShell Script: Executes deployment operations on the Windows server.?
  • Windows Task Scheduler: Schedules PowerShell scripts to wake up and run at a given frequency.?
  • Webhook Notifications: Notifies build and deployment status to Slack or MS Teams.?

Connections:?

  • Azure DevOps to Jenkins: Source code retrieval from Azure DevOps by the Jenkins server.?
  • Jenkins to Windows IIS Server: Deployment of the web application from Jenkins to the Windows IIS server via SMB share.?
  • Jenkins to Slack/MS Teams: Notifications sent to Slack or MS Teams by Jenkins upon deployment completion.?

Low-Level Design (LLD)??

Jenkins Pipeline:?

  • Prepare Environment: Sets up the Jenkins workspace and installs necessary tools like smbclient.?
  • Checkout Code: Fetches the source code from Azure DevOps repository.?
  • Build Application: Compiles and packages the web application using dotnet publish.?
  • Deploy to IIS: Transfers the build artifacts to IIS server (using smbclient), waits for PowerShell to Complete deployment and notify status via SMB shares.?
  • Notify Deployment Status: Sends deployment status notifications to Slack or MS Teams.?

Windows IIS Server Operations:?

  • Stop IIS: Halts the IIS server operations before deployment using PowerShell script.?

  • Transfer Files: Utilizes smbclient to copy build artifacts from the SMB share to the IIS server.?
  • Start IIS: Restarts the IIS server post-deployment to resume web hosting operations through PowerShell script execution.?

PowerShell Script Execution:?

  • Windows Task Scheduler: Schedules the execution of a PowerShell script to monitor the SMB share for new build artifacts.?
  • Check Current and Deployed Build: The PowerShell script compares the current build number with the deployed build number and triggers deployment if a newer build is available.?

Security Considerations:?

  • Credentials Handling: Emphasizes the secure handling of credentials within Jenkins using the Credentials Plugin.?
  • Ports Open: Specifies the necessity of opening ports 80 (HTTP) and 443 (HTTPS) in AWS Security Groups for communication with the IIS server.?

Testing Environment:?

  • Ubuntu Jenkins Server: Represents the Ubuntu server hosting Jenkins.?
  • Windows IIS Server: Depicts the Windows server hosting IIS.?
  • Software Versions: Specifies the versions of Ubuntu, Jenkins, and Windows Server used in testing.?

Pipeline Breakdown?

Jenkins Pipeline Overview?

The Jenkins pipeline, hosted on an AWS EC2 Ubuntu instance, manages the CI/CD process. It fetches source code from Azure DevOps, builds the application, and deploys it to the Windows IIS server.?

Jenkins Pipeline Stages?

  • Prepare Environment: Sets up the workspace and installs necessary tools, including smbclient.?
  • Checkout Code: Fetches source code from Azure DevOps.?
  • Build Application: Builds the web application using dotnet publish.?
  • Deploy to IIS: Transfers build artifacts to the IIS server using SMB shares.?

  • Notify Deployment Status: Sends deployment status notifications to Slack or MS Teams via webhooks.?

Jenkins Requirements?

Ensure the following are installed on the Jenkins server:?

  • Git Plugin: For performing Git operations.?
  • Credentials Plugin: For securely handling credentials.?
  • Pipeline Plugin: For defining and running pipelines.?
  • Azure DevOps Plugin: For integrating with Azure DevOps.?
  • .NET SDK Support Plugin: For building .NET applications.?
  • Pipeline Steps Plugin: For additional pipeline functionalities.?
  • Pipeline Stage View Plugin: For visualizing pipeline stages.?
  • smbclient: For transferring files via SMB.?
  • Install smbclient on Jenkins (Ubuntu)?

```sh?

snap apt-get install smbclient --classic?

```?

  • Install dotnet on Jenkins (Ubuntu)??

This is required as the .NET SDK plugin does not work correctly in some environments.?

```sh?

snap apt-get install dotnet --classic?

```?

PowerShell Deployment Script Overview?

A PowerShell script automates deployment operations on the Windows IIS server. It facilitates copying new builds from SMB shares to the IIS web root, recycles application pools in IIS, and ensures seamless deployment. PowerShell script performs following steps:?

Prepare and Backup:?

  • ?Compare Builds: Checks if the current build matches the deployed build; exits if they match.?
  • ?Backup: Creates backups of the existing deployment.?
  • ?Copy Files: Prepares and copies new build files to temporary directories.?

Deploy:?

  • ?Stop IIS: Halts IIS or recycles application pools.?
  • ?Move Files: Transfers files to deployment directories.?
  • ?Start IIS: Restart IIS to apply changes.??

Cleanup and Update:?

  • ?Clean Up: Removes temporary directories.?
  • Update Marker: Syncs the deployed build marker with the current build.?

?

Scheduling PowerShell Script via Windows Task Scheduler?

For detailed instructions on scheduling a PowerShell script using Windows Task Scheduler, refer to? Microsoft documentation on creating scheduled tasks .?

Script Execution and Monitoring?

Once scheduled, the PowerShell script performs the following actions:?

  • Wake Up: Task Scheduler invokes the script at specified intervals.?
  • Check SMB Share: The script compares the currentBuild and deployedBuild files in the SMB share to detect new builds.?

  • Deploy New Build: If a new build is detected (`currentBuild` > deployedBuild), the script initiates deployment.?
  • Update Deployment Status: After successful deployment, the script updates the deployedBuild file in the SMB share with the new build number so that Jenkins Job assumes completion of Deployment of new build and proceeds with further steps.??

This automation streamlines deployment processes, minimizing manual intervention and enhancing deployment efficiency.?

Best Practices?

  • Version Control: Maintain Jenkinsfile and scripts in version control.?
  • Testing: Test pipeline and scripts in staging before production.?
  • Backups: Regularly back up the IIS server.?
  • Monitoring: Implement monitoring for issue detection.?
  • Secure Credentials: Use Jenkins Credentials Plugin and withCredentials blocks to secure sensitive data.?

Conclusion?

This article provides a comprehensive guide for setting up an automated deployment pipeline. By following these steps, DevOps engineers can ensure efficient and reliable deployments from Azure DevOps to the Windows IIS server, enhancing the overall software delivery process.?

要查看或添加评论,请登录

社区洞察