Team Services | TFS 2017 | TFS 2015 | Previous versions (XAML builds)
Run a PowerShell script
The build agent must have the following capability:
|Script filename||Specify the path to the script to you want to run. The path must be a fully qualified path or a valid path relative to the default working directory. In Team Foundation Build, this directory is $(Build.SourcesDirectory).|
|Arguments||Specify arguments to pass to the script. You can use ordinal or named parameters.|
|Working folder||Specify the working directory in which you want to run the script. If you leave it empty, the working directory is the folder where the script is located.|
test.ps1 at the root of your repo:
Write-Host "Hello World from $Env:AGENT_NAME." Write-Host "My ID is $Env:AGENT_ID." Write-Host "AGENT_WORKFOLDER contents:" gci $Env:AGENT_WORKFOLDER Write-Host "AGENT_BUILDDIRECTORY contents:" gci $Env:AGENT_BUILDDIRECTORY Write-Host "BUILD_SOURCESDIRECTORY contents:" gci $Env:BUILD_SOURCESDIRECTORY Write-Host "Over and out."
On the Build tab of a build definition, add this step:
Where can I learn about PowerShell scripts?
Q: I'm having problems. How can I troubleshoot them?
A: Try this:
On the variables tab, add
system.debugand set it to
true. Select to allow at queue time.
In the explorer tab, view your completed build and click the build step to view its output.
The control options arguments described above can also be useful when you're trying to isolate a problem.
Q: How do variables work? What variables are available for me to use in the arguments?
$(Agent.BuildDirectory) are just a few of the variables you can use. See Variables.
Do I need a build agent?
You need at least one agent to run your build. Get an agent.
I can't select a default agent queue and I can't queue my build. How do I fix this?