Search code examples
azure-devopsazure-pipelines

Can I Use Deployment Pools in Yaml?


We just recently converted our Azure box to the latest version. As such, we've been going through our projects and hooking the pipelines back up (since our server changed as well). While we're doing this, I noticed that our newer applications are using .Net Core, so their builds and deployments are yaml files, not the classic pipelines. Because of this, the projects were using Environments that were deployment agents directly on the boxes we wanted to publish and deploy out to.

That process was working before, but since none of us really understand Azure DevOps that well, we were wondering why the yaml files couldn't use the Deployment Pools already set up. The older, classic pipelines all targeted those. And it sounds like a better option: letting one deployment agent handle all of the deployments to a single box rather than having multiple deployment agents running on one box.

However, looking around for this, I can't find anything pointing me to using deployment pools in relation with yaml. Yaml, it seems, only works for environments that are specifically updated and created for the project. Can someone tell me if what I'm wanting to do is even possible? And if it is, how do I set up my yaml file to do this? I will post what my yaml file looks like down below, so you know what it was doing before with environments.

trigger:
- none

variables:
  IISWebsiteName: 'DevOpsApplications'
  IISWebApplicationName: 'TestApplication'
resources:
  pipelines:
    - pipeline: 'buildPipeline'
      project: 'TestProjectApplication'
      source: 'Build Pipeline'
      branch: trunk
 stages:
   - stage: DeployWebsite
     displayName: 'Deploy Website'
     pool:
       name: 'Default'
     jobs:
     - deployment: DeployWebsite
       displayName: 'Deploy Website'
       environment: 'THISWASTHEENVIRONMENT_BEFORECHANGE'
       strategy:
         runOnce:
           deploy:
             steps:
               - checkout: none
               - download: 'buildPipeline'
                 name: 'DownloadBuildArtifacts'
                 displayName: 'Download Build Artifacts'
                 artifact: 'TestAppArtifact'
               - task: IISWebAppManagementOnMachineGroup@0
                 name: 'StopIIS'
                 displayName: 'Stop Website'
                 inputs:
                   IISDeploymentType: 'IISWebsite'
                   ActionIISWebsite: 'StopWebsite'
                   StartStopWebsiteName: '${{ variables.IISWebsiteName }}'
               - task: IISWebAppManagementOnMachineGroup@0
                 name: 'DeployWebService'
                 displayName: 'Deploy Web Service Application'
                 inputs:
                   WebSiteName: '${{ variables.IISWebsiteName }}'
                   VirtualApplication: '${{ variables.IISWebApplicationName }}'
                   Package: '$(Pipeline.Workspace)\buildPipeline\TestApplication\TestProject'
                   TakAppOfflineFlag: true
               - task:
                 name: 'StartIIS'
                 displayName: 'Start IIS Website'
                 inputs:
                   IISDeploymentType: 'IISWebsite'
                   ActionIISWebsite: 'StartWebsite'
                   StartStopWebsiteName: '${{ variables.IISWebsiteName }}'

Solution

  • When adding VM resources into a pipeline environment, it generates the corresponding deployment pool to the id of the environment.

    Image

    In a YAML pipeline, we can reference the environment and configure the deployment jobs to scale out targeting those VM resources. But we cannot run deployment jobs of the YAML pipeline in the deployment pools generated by the deployment groups for release pipelines.

    
    jobs:
    - deployment: Deploy
      environment:
        name: E-Test
        resourceType: virtualMachine
      strategy:
        runOnce:
          deploy:
            steps:
            - script: |
                echo "Running deployment job of YAML pipeline on VM resources of pipeline environment."