Introduction
In modern cloud environments, automating infrastructure deployment using CI/CD pipelines is a key practice for efficient and scalable operations. In this blog, we will walk you through the process of deploying a Windows Server with IIS (Internet Information Services) installed on Azure using an Azure DevOps pipeline. By leveraging ARM templates and Azure DevOps, we can automate the creation and configuration of the VM. Let’s dive into the steps needed to set up this infrastructure using continuous integration and continuous deployment (CI/CD).
Step 1: Set Up Your Azure DevOps Organization
1.1 Create an Azure DevOps Organization
First, log in to the Azure portal using your lab credentials. We’ll use Azure DevOps for automating the entire deployment process.
- In the search bar, search for Azure DevOps and select Azure DevOps organizations.
- On the Azure DevOps homepage, click on My Azure DevOps Organizations.
- Confirm your account details and click Continue.
- On the Get started with Azure DevOps page, click Create new organization, accept the terms of service, and fill out the CAPTCHA.
- After verification, click Continue and your organization will be created.
1.2 Create a New Project
- Once your organization is set up, create a new project named MyFirstProject and set the visibility to Private.
- Click Create project to finalize.
Step 2: Enable Classic Pipeline Editor
Before we begin setting up pipelines, we need to enable the classic pipeline editor for your organization.
- Click on Azure DevOps in the top-left corner.
- Navigate to Organization settings in the bottom-left corner.
- Under Pipelines, click Settings, and toggle off the options for Disable creation of classic build pipelines and Disable creation of classic release pipelines.
Now, return to your project page, and you’re ready to proceed.
Step 3: Push Code to Azure Repos
- In the sidebar, select Repos.
- You will notice an empty repository for the project. Click Import to add code from an external repository.
- Paste the following repository URL:
https://github.com/devops81/powershell-dsc-azure.git and click Import.
Step 4: Create a Personal Access Token
To authenticate the Azure DevOps agent, you need to create a Personal Access Token (PAT):
- In the top-right corner, click on the User settings icon and select Personal access tokens.
- Click New Token and fill in the details:
- Name: Enter
agentvm. - Scopes: Select Full access.
- Name: Enter
- After creating the token, copy it and store it securely.
Step 5: Set Up the Agent
To interact with Azure DevOps, you need to install and configure an agent on your machine.
5.1 Download and Configure the Agent
- Go to the Agent pools section under Pipelines settings.
- Select the Default pool, then click New agent.
- Choose Windows and copy the download link for the agent.
- Use Remote Desktop (RDP) to connect to your VM and open Windows PowerShell.
- Download the agent using the following command:
Invoke-WebRequest -uri <AGENT_URI> -OutFile "$HOME\Downloads\vsts-agent-win-x64-<version_number>.zip" - Extract the agent and configure it:
cd C:\ mkdir C:\agent ; cd C:\agent Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$HOME\Downloads\vsts-agent-win-x64-<version_number>.zip", "$PWD") - Run the configuration script:
.\config.cmd - During the configuration, enter your Azure DevOps URL and the Personal Access Token you created earlier.
Step 6: Create Build and Release Pipelines
6.1 Create the Build Pipeline
- In Azure DevOps, navigate to Pipelines and click Create Pipeline.
- Choose Use the classic editor.
- Set the repository to Azure Repos Git and select MyFirstProject.
- For the Agent pool, select Default.
- Add tasks like Copy files and Publish build artifacts to copy the necessary files for your VM deployment.
6.2 Run the Build Pipeline
- Save and queue the build. The build process will take a few minutes.
- Once completed, check the generated artifact to ensure the files are ready for deployment.
Step 7: Create a Service Connection
You need a service connection to link Azure DevOps to your Azure subscription.
- Open Cloud Shell from the Azure portal and initialize PowerShell.
- Retrieve your Subscription ID:
Get-AzSubscription - In Azure DevOps, go to Project settings > Service connections and create a new Azure Resource Manager service connection, using the subscription details retrieved earlier.
Step 8: Create the Release Pipeline
- Navigate to Azure Pipelines > Releases and create a new pipeline.
- Add an artifact from the Build pipeline you created earlier.
- Select the ARM template deployment task and configure it to deploy the resources to Azure using the provided ARM template.
Step 9: Run the Release Pipeline
- Create a new release in the Release Pipeline.
- Monitor the release logs as the pipeline runs. The deployment should take around 10 minutes to complete.
Step 10: Verify IIS Installation on the VM
Once the release pipeline completes successfully, you can verify the IIS installation:
- In the Azure portal, navigate to Virtual Machines and select the VM you deployed (e.g., win2019-iis-vm-1).
- Use RDP to log in to the VM using the admin credentials you provided earlier.
- From the Server Manager dashboard, check if IIS is installed. You should see IIS listed in the left navigation panel.
- Test the IIS splash page by navigating to
http://localhost.
Conclusion
By following these steps, you have successfully automated the deployment of a Windows Server with IIS using Azure DevOps. This CI/CD pipeline ensures that your infrastructure is reproducible, scalable, and quickly deployed. With Azure DevOps, the possibilities for automating and managing your cloud infrastructure are limitless, saving you time and ensuring consistency across environments.
