Use Azure Pipelines to Deploy IIS Server

The following blog post will show you an Azure Pipeline that deploys an application to an IIS Website hosted on a virtual machine.

In our use case, we have an IIS Web Server that runs the Azure agent and is set up as an environment. Our goal is to deploy a .NET application into an IIS website (default web site)

Azure Pipeline (YAML)

The following YAML pipeline has two tasks and a deployment job to an IIS Server setup as an environment. The first build task is using MSBuild task to build the code. The second task creates an artifact from the build.

The last job uses DeploytoIIS to deploy the code to an IIS Website.

Note: You can use the following variable in your code to set the IIS website variables.

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Staging'
  websiteName: 'Default Web site'
  projectName: 'default'
  appPoolName: 'DefaultAppPool'

Pipeline

        - task: [email protected]
          inputs:
            solution: '$(solution)'
            msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
            platform: '$(buildPlatform)'
            configuration: '$(buildConfiguration)'
                
        - task: [email protected]
          inputs:
            PathtoPublish: '$(Build.ArtifactStagingDirectory)'
            ArtifactName: 'drop'
            publishLocation: 'Container'

 
- stage: Deploy
  displayName: Deploy to IIS Server
  dependsOn: Build
  jobs:
  - deployment: DeploytoIIS
    displayName: Deploy the web application to IIS
    environment:
      name: ADD-ENV-NAME
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - task: [email protected]
            inputs:
              buildType: 'current'
              downloadType: 'specific'
              downloadPath: '$(System.ArtifactsDirectory)'
          - task: [email protected]
            displayName: 'Deploy to IIS Website'
            inputs:
              WebSiteName: '$(websiteName)'
              Package: '$(System.ArtifactsDirectory)\**\*.zip'
 

Processing…
Success! You're on the list.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.