Can I use 2 agent pools in my azure pipelines?

Viewed 3738

I've got a single self-hosted agent. Its used as a kind of deployment agent. All release versions of our software gets build by this agent and then copied to a network location.

Question: Is there a way I can utilize both the agent from the 'azure-pipelines' Microsoft hosted pool and my own self-hosted pool in my pipelines?

EDIT

Unfortunately this is not possible at the moment. This is why you should upvote the feature request: https://developercommunity.visualstudio.com/t/allow-agent-pools-to-contain-microsoft-hosted-and/396893

3 Answers

Which benefits do you want to achieve?

Basically, you can use several agent pools in one build/release definition. You just split your definition into several jobs and assign the needed agent pool to the corresponding job.

If you want to dynamically assign different pools from one pipeline to do the same build steps, we can not do that (as Krzysztof mentioned).

You can do hacky thing and use multiple jobs/stages. Jobs/stages will use different pools. You just need to skip depending if it is release version. Note that pipeline skeleton is not tested.

variables:
  ${{ eq(variables['Build.SourceBranch'], 'release/*') }}:
    release_build: True

stages:
- stage: normal
  condition: eq(variables['release_build'], False)
  pool:
    vmImage: 'windows-latest'
  jobs:
    - job: Builds
      steps:
        - template: build.yaml

- stage: release
  condition: eq(variables['release_build'], True)
  pool: My-agent
  jobs:
    - job: Builds
      steps:
        - template: build.yaml
Related