Created
June 21, 2017 19:00
-
-
Save jrr/555aa91f0b990cda0e5dbfd9e07ca5e2 to your computer and use it in GitHub Desktop.
find an executable from a VSTS build task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
Powershell.exe -executionpolicy remotesigned -File "%~dp0\vsts-foobar-path.ps1" | |
set /p foobarPath=< foobar-path.txt | |
PATH=%PATH%;%foobarPath% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.