I have been trying to setup a CICD Pipeline for Business Central and would like to know in runtime what type of Azure DevOps Agent is being used to run the pipeline? (Azure Hosted vs On-Prem Hosted) as this will change the way the Build is done.
Please let me know if this is possible to achieve. So far I have implemented a logic where I check the name of the pipeline and if it starts with "self_hosted" then I know it is an on-prem installation and so.
You can use the value of the predefined variable "Agent.Name
" to identify the agent type:
Hosted Agent
".In certain situations, the self-hosted agents might have been configured with the same name (Hosted Agent
) as the Microsoft-hosted agents. At this time, you also can use the value of the predefined variable "Agent.CloudId
" to identify the agent type:
See below example as reference:
# azure-pipelines.yml
jobs:
- job: A
strategy:
matrix:
WindowsPool:
poolName: WindowsPool # A pool of self-hosted Windows agents.
LinuxPool:
poolName: LinuxPool # A pool of self-hosted Linux agents.
MsHosted:
poolName: 'Azure Pipelines' # The pool of Microsoft-hosted agents.
pool: $(poolName)
steps:
- checkout: none
- pwsh: |
Write-Host "Agent.Name = $(Agent.Name)"
Write-Host "Agent.CloudId = $(Agent.CloudId)"
Write-Host "Agent.MachineName = $(Agent.MachineName)"
Write-Host "Agent.OS = $(Agent.OS)"
Write-Host "Agent.OSArchitecture = $(Agent.OSArchitecture)"
displayName: 'Show Agent Information'