0

Given a user-defined capabilities in some of the self-hosted agent, for example:

Name: InHouse.BuildTools

Value: C:\Program Files (x86)\Build Tools\builder.exe

In the yaml pipeline, how to execute 'C:\Program Files (x86)\Build Tools\builder.exe' by using the variable of $(InHouse.BuildTools) without hard-coding the actual path?

Pok
  • 1,521
  • 1
  • 13
  • 20

1 Answers1

0

Since Azure agent capabilities get set as environment variables (https://learn.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser#capabilities), you could use a powershell script task to write it as an output variable for use later in your pipeline. Something like this should work:

jobs:
- job: A
  steps:
  - powershell: |
     Write-Host "##vso[task.setvariable variable=buildToolsPath;isOutput=true]${env:INHOUSE_BUILDTOOLS}"
    name: getBuildToolsPath
- job: B
  dependsOn: A
  variables:
    buildToolsPathFromJobA: $[ dependencies.A.outputs['getBuildToolsPath.buildToolsPath'] ]  
  steps:
    #use variable as $(buildToolsPathFromJobA) in these steps

(code adapted from https://learn.microsoft.com/en-us/azure/devops/pipelines/process/set-variables-scripts?view=azure-devops&tabs=powershell#set-an-output-variable-for-use-in-future-jobs)