Search code examples
powershellazure-devopsyaml

Is it possible to fetch poolname of current running build in azure devops?


I have a pipeline in which I need to push the agent poolname of the current running build as a variable but couldnt find any predefined variables from azure devops.

Demo-yml-pipeline below:

name: $(BuildID)
trigger: none

pool: Self Hosted Docker (Linux)

steps:
- powershell: |
     Write-Host "want poolname on which the pipeline is running"

Thanks.

Fount Agent.name here but it is returning agentName instead of poolname.


Solution

  • To my knowledge, there is no built in way way to fetch the pool name.

    I can think of two options you could use to obtain it.


    Set an environment variable

    If you have access to the agent, you can create an enviroment variable and reference that in your script.

    In Linux, you can use export poolName=poolValue, and then reference it in powershell. Note that environment variables in linux are case sensitive.

    name: $(BuildID)
    trigger: none
    
    pool: Self Hosted Docker (Linux)
    
    steps:
    - powershell: |
         Write-Host $env:poolName
    

    Store it in a variable

    You can define your pool name in a variable, and use that variable to reference the pool.

    name: $(BuildID)
    trigger: none
    
    variables:
    - name: poolName
      value: 'Self Hosted Docker (Linux)'
    
    pool: $(poolName)
    
    steps:
    - powershell: |
         Write-Host $(poolName)