1
votes

I'm trying to create a proof of concept, deploying an ASP.NET web app (.NET Framework, not .NET Core) to an on-prem Windows server running IIS.

I got it working using a YAML-based build pipeline and a release pipeline which uses the classic GUI. To deploy to the on-prem server I created a deployment group and deployed a self-hosted agent to the target server. Works fine.

My next step is to try to create a YAML-based multistage pipeline, converting the build pipeline to the build stage and writing a brand new deployment stage. As I understand it YAML multistage pipelines don't support deployment groups and instead I have to create an environment with a Virtual Machine resource. I created the agent on the target server and it registered itself as a resource under the environment, so that setup seems fine. In this case the environment is named "Dev".

I tried running the pipeline and it appeared to work fine, finishing as successful. Logs show the deployment stage downloaded the artifact created in the build stage, and the IIS Web App Manage and IIS Web App Deploy steps ran fine. However, the web app on the target server was not updated. The resource under the Dev environment, representing the target server, is also showing "Never deployed" as the latest job, suggesting the self-hosted agent never pulled down the release.

I assume that as the logs show no error the deployment job is actually running on a Microsoft-hosted agent instead of the self-hosted agent. I can't see where I'm going wrong, given that the Dev environment exists with the self-hosted agent as its only resource. Any hints or suggestions of where I've gone wrong?

Here's the YAML file in its entirety:

trigger:
- '*'

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:TransformWebConfigEnabled=false /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'
    pool:
      vmImage: 'windows-latest'
    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: Dev
    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)

And here are the raw log files for the deployment stage:

2020-06-15T12:15:56.9858347Z ##[section]Starting: Deploy the web application to dev environment
2020-06-15T12:15:57.1573499Z ##[section]Starting: Initialize job
2020-06-15T12:15:57.1574831Z Agent name: 'Hosted Agent'
2020-06-15T12:15:57.1575185Z Agent machine name: 'WIN-5Q96T5JR7AD'
2020-06-15T12:15:57.1575401Z Current agent version: '2.170.1'
2020-06-15T12:15:57.1593854Z Current image version: '20200531.1'
2020-06-15T12:15:57.1601179Z Agent running as: 'VssAdministrator'
2020-06-15T12:15:57.1656829Z Prepare build directory.
2020-06-15T12:15:57.2207188Z Set build variables.
2020-06-15T12:15:57.2242403Z Download all required tasks.
2020-06-15T12:15:57.2403517Z Downloading task: DownloadBuildArtifacts (0.167.2)
2020-06-15T12:15:58.7871306Z Downloading task: IISWebAppManagementOnMachineGroup (0.5.15)
2020-06-15T12:15:58.8604155Z Downloading task: IISWebAppDeploymentOnMachineGroup (0.156.13)
2020-06-15T12:16:00.2584106Z Checking job knob settings.
2020-06-15T12:16:00.2595245Z    Knob: AgentToolsDirectory = C:/hostedtoolcache/windows Source: ${AGENT_TOOLSDIRECTORY} 
2020-06-15T12:16:00.2596590Z    Knob: AgentPerflog = c:\agents\perflog Source: ${VSTS_AGENT_PERFLOG} 
2020-06-15T12:16:00.2597479Z Finished checking job knob settings.
2020-06-15T12:16:00.2963001Z Start tracking orphan processes.
2020-06-15T12:16:00.3045878Z ##[section]Finishing: Initialize job
2020-06-15T12:16:00.3715796Z ##[section]Starting: Download
2020-06-15T12:16:00.4732035Z ==============================================================================
2020-06-15T12:16:00.4732834Z Task         : Download build artifacts
2020-06-15T12:16:00.4733443Z Description  : Download files that were saved as artifacts of a completed build
2020-06-15T12:16:00.4733725Z Version      : 0.167.2
2020-06-15T12:16:00.4734218Z Author       : Microsoft Corporation
2020-06-15T12:16:00.4734834Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/download-build-artifacts
2020-06-15T12:16:00.4735229Z ==============================================================================
2020-06-15T12:16:02.4240789Z Downloading artifacts for build: 206
2020-06-15T12:16:02.4263144Z Downloading items from container resource #/7981806/drop
2020-06-15T12:16:02.4263938Z Downloading artifact drop from: https://dev.azure.com/SimonE0675//_apis/resources/Containers/7981806?itemPath=drop&isShallow=true&api-version=4.1-preview.4
2020-06-15T12:16:02.4268251Z Downloading drop/AspNetDemo.deploy-readme.txt to d:\a\1\drop\AspNetDemo.deploy-readme.txt
2020-06-15T12:16:02.8224843Z Downloading drop/AspNetDemo.deploy.cmd to d:\a\1\drop\AspNetDemo.deploy.cmd
2020-06-15T12:16:02.8547084Z Downloading drop/AspNetDemo.SetParameters.xml to d:\a\1\drop\AspNetDemo.SetParameters.xml
2020-06-15T12:16:03.4437009Z Downloading drop/AspNetDemo.SourceManifest.xml to d:\a\1\drop\AspNetDemo.SourceManifest.xml
2020-06-15T12:16:03.4495772Z Downloading drop/AspNetDemo.zip to d:\a\1\drop\AspNetDemo.zip
2020-06-15T12:16:03.4516280Z Downloaded drop/AspNetDemo.deploy-readme.txt to d:\a\1\drop\AspNetDemo.deploy-readme.txt
2020-06-15T12:16:03.4523121Z Downloaded drop/AspNetDemo.SetParameters.xml to d:\a\1\drop\AspNetDemo.SetParameters.xml
2020-06-15T12:16:03.4525288Z Downloaded drop/AspNetDemo.deploy.cmd to d:\a\1\drop\AspNetDemo.deploy.cmd
2020-06-15T12:16:03.4561228Z Downloaded drop/AspNetDemo.SourceManifest.xml to d:\a\1\drop\AspNetDemo.SourceManifest.xml
2020-06-15T12:16:03.8676511Z Downloaded drop/AspNetDemo.zip to d:\a\1\drop\AspNetDemo.zip
2020-06-15T12:16:04.8013454Z Total Files: 5, Processed: 5, Skipped: 0, Failed: 0, Download time: 3.039 secs, Download size: 5.572MB
2020-06-15T12:16:05.3818312Z Successfully downloaded artifacts to d:\a\1/
2020-06-15T12:16:05.3852498Z ##[section]Finishing: Download
2020-06-15T12:16:05.3893746Z ##[section]Starting: IIS Web App Manage
2020-06-15T12:16:05.4111059Z ==============================================================================
2020-06-15T12:16:05.4111422Z Task         : IIS web app manage
2020-06-15T12:16:05.4111762Z Description  : Create or update websites, web apps, virtual directories, or application pools
2020-06-15T12:16:05.4114396Z Version      : 0.5.15
2020-06-15T12:16:05.4114757Z Author       : Microsoft Corporation
2020-06-15T12:16:05.4115193Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/iis-web-app-management-on-machine-group
2020-06-15T12:16:05.4115883Z ==============================================================================
2020-06-15T12:16:09.1901004Z ##[command]"C:\windows\system32\inetsrv\appcmd.exe"  list site /name:"Default Web Site"
2020-06-15T12:16:09.7275643Z 
2020-06-15T12:16:09.7277066Z 
2020-06-15T12:16:09.7282874Z     Directory: C:\inetpub\wwwroot
2020-06-15T12:16:09.7285603Z 
2020-06-15T12:16:09.7286457Z 
2020-06-15T12:16:09.7305926Z Mode                LastWriteTime         Length Name                                                                  
2020-06-15T12:16:09.7323105Z ----                -------------         ------ ----                                                                  
2020-06-15T12:16:09.7339223Z d-----        6/15/2020  12:16 PM                AspNetDemo                                                            
2020-06-15T12:16:09.7532322Z ##[command]"C:\windows\system32\inetsrv\appcmd.exe"  set site /site.name:"Default Web Site" -[path='/'].[path='/'].physicalPath:"%SystemDrive%\inetpub\wwwroot\AspNetDemo" -[path='/'].[path='/'].userName: -[path='/'].[path='/'].password:
2020-06-15T12:16:10.4767779Z SITE object "Default Web Site" changed
2020-06-15T12:16:10.5022726Z 
2020-06-15T12:16:10.5069765Z 
2020-06-15T12:16:10.5329739Z ##[section]Finishing: IIS Web App Manage
2020-06-15T12:16:10.5548276Z ##[section]Starting: IIS Web App Deploy
2020-06-15T12:16:10.5701088Z ==============================================================================
2020-06-15T12:16:10.5701408Z Task         : IIS web app deploy
2020-06-15T12:16:10.5701716Z Description  : Deploy a website or web application using Web Deploy
2020-06-15T12:16:10.5701975Z Version      : 0.156.13
2020-06-15T12:16:10.5702225Z Author       : Microsoft Corporation
2020-06-15T12:16:10.5702612Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/deploy/iis-web-app-deployment-on-machine-group
2020-06-15T12:16:10.5703027Z ==============================================================================
2020-06-15T12:16:12.0232544Z ConnectionString attributes in Web.config is parameterized by default. Note that the transformation has no effect on connectionString attributes as the value is overridden during deployment by 'Parameters.xml or 'SetParameters.xml' files. You can disable the auto-parameterization by setting /p:AutoParameterizationWebConfigConnectionStrings=False during MSBuild package generation.
2020-06-15T12:16:12.0631887Z [command]d:\a\_tasks\IISWebAppDeploymentOnMachineGroup_1b467810-6725-4b6d-accd-886174c09bba\0.156.13\ctt\ctt.exe s:d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config t:d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Release.config d:d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config pw i verbose
2020-06-15T12:16:12.4770510Z Start tranformation to 'd:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config'.
2020-06-15T12:16:12.4771847Z Source file: 'd:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config'.
2020-06-15T12:16:12.4773080Z Transform  file: 'd:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Release.config'.
2020-06-15T12:16:12.4774325Z Transformation task is using encoding 'System.Text.UTF8Encoding'. Change encoding in source file, or use the 'encoding' parameter if you want to change encoding.
2020-06-15T12:16:12.4775273Z Executing RemoveAttributes (transform line 18, 18)
2020-06-15T12:16:12.4776821Z on /configuration/system.web/compilation
2020-06-15T12:16:12.4777702Z Applying to 'compilation' element (no source line info)
2020-06-15T12:16:12.4778465Z Removed 'debug' attribute
2020-06-15T12:16:12.4778827Z Removed 1 attributes
2020-06-15T12:16:12.4779125Z Done executing RemoveAttributes
2020-06-15T12:16:12.4779863Z XML Transformations applied successfully
2020-06-15T12:16:12.5028504Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Debug.config
2020-06-15T12:16:12.5104251Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Debug.config
2020-06-15T12:16:12.5105110Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Dev.config
2020-06-15T12:16:12.5138107Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5157111Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Dev.config
2020-06-15T12:16:12.5158089Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Release.config
2020-06-15T12:16:12.5177323Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Release.config
2020-06-15T12:16:12.5187991Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Test.config
2020-06-15T12:16:12.5191087Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5192067Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.Test.config
2020-06-15T12:16:12.5192706Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config
2020-06-15T12:16:12.5208981Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5221909Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\Web.config
2020-06-15T12:16:12.5223143Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Debug.config
2020-06-15T12:16:12.5226584Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Debug.config
2020-06-15T12:16:12.5227609Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Dev.config
2020-06-15T12:16:12.5233500Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5238472Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Dev.config
2020-06-15T12:16:12.5240963Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Release.config
2020-06-15T12:16:12.5247520Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Release.config
2020-06-15T12:16:12.5255360Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Test.config
2020-06-15T12:16:12.5285847Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5289812Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\Web.Test.config
2020-06-15T12:16:12.5293438Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\VBCSCompiler.exe.config
2020-06-15T12:16:12.5327539Z Processing substitution for xml node : appSettings
2020-06-15T12:16:12.5335594Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\VBCSCompiler.exe.config
2020-06-15T12:16:12.5338157Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\csc.exe.config
2020-06-15T12:16:12.5371336Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\csc.exe.config
2020-06-15T12:16:12.5371992Z Initiated variable substitution in config file : d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\vbc.exe.config
2020-06-15T12:16:12.5389975Z Skipped Updating file: d:\a\_temp\temp_web_package_9405406238180971\Content\d_C\a\1\s\AspNetDemo\obj\Release\Package\PackageTmp\bin\roslyn\vbc.exe.config
2020-06-15T12:16:12.5390858Z XML variable substitution applied successfully.
2020-06-15T12:16:13.6524609Z [command]"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='d:\a\1\s\temp_web_package_590126440620167.zip' -dest:auto -setParam:name='IIS Web Application Name',value='Default Web Site/AspNetDemo' -enableRule:AppOffline
2020-06-15T12:16:16.1656560Z Info: Adding sitemanifest (sitemanifest).
2020-06-15T12:16:16.3688794Z Info: Creating application (Default Web Site/AspNetDemo)
2020-06-15T12:16:16.3855513Z Info: Adding virtual path (Default Web Site/AspNetDemo)
2020-06-15T12:16:16.4371591Z Info: Adding directory (Default Web Site/AspNetDemo).
2020-06-15T12:16:16.4845399Z Info: Adding directory (Default Web Site/AspNetDemo\bin).
2020-06-15T12:16:16.4883541Z Info: Adding file (Default Web Site/AspNetDemo\bin\Demo2.dll).
2020-06-15T12:16:16.5070593Z Info: Adding file (Default Web Site/AspNetDemo\bin\Demo2.pdb).
2020-06-15T12:16:16.5080200Z Info: Adding file (Default Web Site/AspNetDemo\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll).
2020-06-15T12:16:16.5098373Z Info: Adding directory (Default Web Site/AspNetDemo\bin\roslyn).
2020-06-15T12:16:16.5109779Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\csc.exe).
2020-06-15T12:16:16.5130856Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\csc.exe.config).
2020-06-15T12:16:16.5139616Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\csc.rsp).
2020-06-15T12:16:16.5148847Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\csi.exe).
2020-06-15T12:16:16.5156562Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\csi.rsp).
2020-06-15T12:16:16.5168651Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.Build.Tasks.CodeAnalysis.dll).
2020-06-15T12:16:16.5229952Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CodeAnalysis.CSharp.dll).
2020-06-15T12:16:16.5971326Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CodeAnalysis.CSharp.Scripting.dll).
2020-06-15T12:16:16.6103919Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CodeAnalysis.dll).
2020-06-15T12:16:16.6490047Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CodeAnalysis.Scripting.dll).
2020-06-15T12:16:16.6641545Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CodeAnalysis.VisualBasic.dll).
2020-06-15T12:16:16.7788705Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.CSharp.Core.targets).
2020-06-15T12:16:16.7866312Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.DiaSymReader.Native.amd64.dll).
2020-06-15T12:16:16.8908394Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.DiaSymReader.Native.x86.dll).
2020-06-15T12:16:16.9128717Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\Microsoft.VisualBasic.Core.targets).
2020-06-15T12:16:16.9136216Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.AppContext.dll).
2020-06-15T12:16:17.0293466Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.Collections.Immutable.dll).
2020-06-15T12:16:17.0358896Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.Diagnostics.StackTrace.dll).
2020-06-15T12:16:17.0397999Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.IO.FileSystem.dll).
2020-06-15T12:16:17.0408374Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.IO.FileSystem.Primitives.dll).
2020-06-15T12:16:17.0429135Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\System.Reflection.Metadata.dll).
2020-06-15T12:16:17.0508174Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\vbc.exe).
2020-06-15T12:16:17.0524962Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\vbc.exe.config).
2020-06-15T12:16:17.0537599Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\vbc.rsp).
2020-06-15T12:16:17.0544089Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\VBCSCompiler.exe).
2020-06-15T12:16:17.0567886Z Info: Adding file (Default Web Site/AspNetDemo\bin\roslyn\VBCSCompiler.exe.config).
2020-06-15T12:16:17.0587023Z Info: Adding file (Default Web Site/AspNetDemo\bin\Web.Debug.config).
2020-06-15T12:16:17.0657739Z Info: Adding file (Default Web Site/AspNetDemo\bin\Web.Dev.config).
2020-06-15T12:16:17.0696168Z Info: Adding file (Default Web Site/AspNetDemo\bin\Web.Release.config).
2020-06-15T12:16:17.0704103Z Info: Adding file (Default Web Site/AspNetDemo\bin\Web.Test.config).
2020-06-15T12:16:17.0711307Z Info: Adding file (Default Web Site/AspNetDemo\Default.aspx).
2020-06-15T12:16:17.0718585Z Info: Adding file (Default Web Site/AspNetDemo\Web.config).
2020-06-15T12:16:17.0737537Z Info: Adding file (Default Web Site/AspNetDemo\Web.Debug.config).
2020-06-15T12:16:17.0914599Z Info: Adding file (Default Web Site/AspNetDemo\Web.Dev.config).
2020-06-15T12:16:17.0921332Z Info: Adding file (Default Web Site/AspNetDemo\Web.Release.config).
2020-06-15T12:16:17.0928434Z Info: Adding file (Default Web Site/AspNetDemo\Web.Test.config).
2020-06-15T12:16:17.0948303Z Info: Adding ACLs for path (Default Web Site/AspNetDemo)
2020-06-15T12:16:17.1479606Z Info: Adding ACLs for path (Default Web Site/AspNetDemo)
2020-06-15T12:16:17.4606954Z Total changes: 47 (46 added, 0 deleted, 1 updated, 0 parameters changed, 14818941 bytes copied)
2020-06-15T12:16:18.3963762Z ##[section]Finishing: IIS Web App Deploy
2020-06-15T12:16:18.4137177Z ##[section]Starting: Finalize Job
2020-06-15T12:16:18.4180998Z Cleaning up task key
2020-06-15T12:16:18.4182925Z Start cleaning up orphan processes.
2020-06-15T12:16:18.4271669Z ##[section]Finishing: Finalize Job
2020-06-15T12:16:18.4320625Z ##[section]Finishing: Deploy the web application to dev environment

I notice the line in the logs, near the top, saying Agent machine name: 'WIN-5Q96T5JR7AD'. That is not the name of the on-prem server running the self-hosted agent so I assume it must be a Microsoft-hosted agent.

2

2 Answers

1
votes

An environment is a collection of resources that can be targeted by deployments from a pipeline. Environments can include Kubernetes clusters, Azure web apps, virtual machines, databases.

In other words, need to tell the pipeline which resource you are going to deploy to. In your case should be Virtual machines. (Since you have mentioned you create an environment with a Virtual Machine resource.)

A sample referencing the environment and VM resources in a pipeline YAML. .

jobs:  
- deployment: VMDeploy
  displayName: web
  environment:
    name:  VMenv
    resourceType: VirtualMachine
    tags: web1
  strategy:

More details please refer our official tutorial here-- Environment - virtual machine resource

In your case, you just specify an environment, deployment job are used to target an entire environment.

And you have specify pool: vmImage: 'windows-latest', so the deployment job finally target the host agent pool which include windows-latest vmImage, not your created VM resource.

That's why deployment job is actually running on a Microsoft-hosted agent instead of the self-hosted agent.

0
votes

I found, through trial and error, a fix: In the Deploy stage, specify the resourceType for the environment.

In the Deploy stage the environment info was:

environment: Dev

It now becomes:

environment:
  name: Dev
  resourceType: VirtualMachine

I don't know why it is necessary to specify the resourceType, or if this is a kludge and there is a more elegant way to fix the issue. However, the pipeline now works consistently.