Search code examples
azure-pipelinesazure-devops-self-hosted-agentazure-pipelines-yaml

Can YAML Pipeline detect cloud vs Self-Hosted build?


Is it possible to determine within a single YAML Pipeline whether the agent is running self-hosted or in a cloud build? If so, how would one go about determining that?

I need my pipeline to work in both locations but certain steps must only occur if I'm building on one or the other.


Solution

  • I can't find directly solution, but it could be done using conditions and agent variables.

    For example I have Hosted Agent in my agents pool:

    enter image description here

    And in YAML I can use this name to condition running step depents on it:

    steps:
    - script: dotnet build --configuration $(buildConfiguration)
      condition: eq(variables['Agent.Name'],'Hosted Agent') 
      displayName: 'dotnet build $(buildConfiguration)'