Skip to content

Instantly share code, notes, and snippets.

@jrr
Created June 21, 2017 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrr/555aa91f0b990cda0e5dbfd9e07ca5e2 to your computer and use it in GitHub Desktop.
Save jrr/555aa91f0b990cda0e5dbfd9e07ca5e2 to your computer and use it in GitHub Desktop.
find an executable from a VSTS build task
@echo off
Powershell.exe -executionpolicy remotesigned -File "%~dp0\vsts-foobar-path.ps1"
set /p foobarPath=< foobar-path.txt
PATH=%PATH%;%foobarPath%
# We're looking for the directory housing the foobar VSTS build task.
# At the time of this writing, it lives within the directory referenced by the
# AGENT_WORKFOLDER env var.
# (if this breaks in the future, maybe look at other variables here:)
# https://www.visualstudio.com/en-us/docs/build/define/variables
# NOTE! The task will only be present if the build has a foobar build step.
$searchDir = [environment]::GetEnvironmentVariable("AGENT_WORKFOLDER")
$search = Get-ChildItem -Path $searchDir -Recurse -Include "foobar.exe"
$foobarPath = $search.DirectoryName
Write-Host "Found foobar.exe at" $foobarPath
$outFile = "foobar-path.txt"
[System.IO.File]::WriteAllText($outFile, $foobarPath)
Write-Host 'wrote path to' $outFile
@jrr
Copy link
Author

jrr commented Jun 21, 2017

We wanted an .exe that comes with a VSTS build step to be available in other build steps. Together, these scripts find it and add it its path to PATH.

To use this, call the .bat from a Batch Script build step, with the Modify environment option enabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment