4
votes

I am following the tutorial for the IIS web deploy pipeline in the url below:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/iis-web-app-deployment-on-machine-group?view=azure-devops

if you see the parameter list, there does not seems to have any deployment group parameter. Therefore, How do I know / control in which server that the result of the deployment goes? Thx

  • task: IISWebAppDeploymentOnMachineGroup@0 inputs:

    webSiteName:

    virtualApplication: # Optional

    package: '$(System.DefaultWorkingDirectory)***.zip'

    setParametersFile: # Optional

    removeAdditionalFilesFlag: false # Optional

    excludeFilesFromAppDataFlag: false # Optional

    takeAppOfflineFlag: false # Optional

    additionalArguments: # Optional

    xmlTransformation: # Optional

    xmlVariableSubstitution: # Optional

    jSONFiles: # Optional

I want it to deploy to my "Dev" group as per screenshot below. If YAML can't deploy to deployment group, where is the default deployment location (ie, which computer?)

Let's say that I want to deploy to my PC , how do I direct the deployment to go to my localbox and put it under C:/publish ?

enter image description here

3

3 Answers

13
votes

As at June 2020 the YAML-based multistage pipeline does not support deployment groups. However, the YAML-based pipeline has an alternative: Environments.

You can create an Environment manually, under Azure Pipelines > Environments. Once you have created the Environment you can add Resources underneath it. At the moment there are only two types of resources supported: Kubernetes and Virtual Machines. The Virtual Machine resource type is a bit misleading: It can be a virtual machine but it can also be an on-prem physical server. If you're deploying to IIS you'll need to create a Virtual Machine resource.

Creating a Virtual Machine resource under an Environment is very much like adding a target to a Deployment Group: When you add the Virtual Machine resource to the Environment it will generate a PowerShell script that you copy to the target server and run there as administrator. Running that script will create a self-hosted agent on the target server and will register that agent as a Resource under the Environment.

This process is almost identical to the process of adding a target to a Deployment Group.

In the YAML file specify the environment under the deployment job. It's not enough to specify the environment by name. You have to also specify the resourceType for the Environment as well as the name.

Here is my YAML for the build and deployment stages:

trigger:
- master

stages:
- stage: 'Build'
  displayName: 'Build the web application'
  
  jobs:
  - job: 'Build'
    displayName: 'Build job'
    
    pool:
      vmImage: 'windows-latest'
    
    variables:
      solution: '**/*.sln'
      buildPlatform: 'Any CPU'
      buildConfiguration: 'Release'
    
    steps:
    - task: NuGetToolInstaller@1
    
    - task: NuGetCommand@2
      inputs:
        restoreSolution: '$(solution)'
    
    - task: VSBuild@1
      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: VSTest@2
      inputs:
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
        
    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- stage: 'Deploy'
  displayName: 'Deploy the web application'
  dependsOn: Build
  jobs:
  - deployment: 'DeployToDev'
    displayName: 'Deploy the web application to dev environment'
    variables:
      Parameters.IISDeploymentType: 'IISWebsite'
      Parameters.ActionIISWebsite: 'CreateOrUpdateWebsite'
      Parameters.WebsiteName: 'Default Web Site'
      Parameters.WebsitePhysicalPath: '%SystemDrive%\inetpub\wwwroot\AspNetDemo'
      Parameters.AddBinding: false
      Parameters.VirtualPathForApplication: '/AspNetDemo'
      Parameters.AppPoolName: ''
      Parameters.VirtualApplication: 'AspNetDemo'
      Parameters.Package: '$(Pipeline.Workspace)\drop\*.zip'
      Parameters.RemoveAdditionalFilesFlag: true
      Parameters.TakeAppOfflineFlag: true
      Parameters.XmlTransformation: true
      Parameters.XmlVariableSubstitution: true
    environment:
      name: Dev
      resourceType: VirtualMachine
    strategy:
      runOnce:
        deploy:
          steps:
          - download: current
            artifact: drop
            
          - task: IISWebAppManagementOnMachineGroup@0
            displayName: 'IIS Web App Manage'
            inputs:
              IISDeploymentType: '$(Parameters.IISDeploymentType)'
              ActionIISWebsite: '$(Parameters.ActionIISWebsite)'
              WebsiteName: '$(Parameters.WebsiteName)'
              WebsitePhysicalPath: '$(Parameters.WebsitePhysicalPath)'
              AddBinding: $(Parameters.AddBinding)
              ParentWebsiteNameForVD: '$(Parameters.WebsiteName)'
              VirtualPathForVD: '$(Parameters.VirtualPathForApplication)'
              ParentWebsiteNameForApplication: '$(Parameters.WebsiteName)'
              VirtualPathForApplication: '$(Parameters.VirtualPathForApplication)'
              AppPoolName: '$(Parameters.AppPoolName)'

          - task: IISWebAppDeploymentOnMachineGroup@0
            displayName: 'IIS Web App Deploy'
            inputs:
              WebSiteName: '$(Parameters.WebsiteName)'
              VirtualApplication: '$(Parameters.VirtualApplication)'
              Package: '$(Parameters.Package)'
              RemoveAdditionalFilesFlag: $(Parameters.RemoveAdditionalFilesFlag)
              TakeAppOfflineFlag: $(Parameters.TakeAppOfflineFlag)
              XmlTransformation: $(Parameters.XmlTransformation)
              XmlVariableSubstitution: $(Parameters.XmlVariableSubstitution)

Note the environment information in the deployment stage, specifying the name (Dev) and the resourceType (VirtualMachine):

environment:
  name: Dev
  resourceType: VirtualMachine
2
votes

YAML does not support deployment groups. If you want to use deployment groups, you can't use YAML.

1
votes

Daniell is right, It seems at this moment YAML can't do the release to deployment group The workaround is as below:

add the following code in the build:

  • task: PublishPipelineArtifact@1 inputs: targetPath: '$(Pipeline.Workspace)' publishLocation: 'pipeline'

  • task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'drop' publishLocation: 'Container'

  • task: ArchiveFiles@2 inputs: rootFolderOrFile: '$(Build.BinariesDirectory)' includeRootFolder: true archiveType: 'zip' archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip' replaceExistingArchive: true

and then you can go to the release , use iis web deploy, ensure that the correct artefact is used in step 1 and choose your package folder. You should be able to see the artifact that you built.