Reputation: 450
We are using a Microsoft Hosted Agent to run a build pipeline for an automated test scenario for our application. What we would like to achieve is, having our automation procedure, to download a file (from a headless chrome browser), then navigate to the path where it is downloaded and open it.
How could I find the path where the files are being downloaded inside the Agent?
Upvotes: 4
Views: 27877
Reputation: 30
I found the answer partly through this question, and one I asked which was asking exactly the same thing, but for me, it was: C:\Users\VssAdministrator\Downloads
Upvotes: 0
Reputation: 1376
Quick compilation of list of pre-defined variables related to paths for the build on linux and windows self hosted agents from official doc link.
The one you are looking is Agent.BuildDirectory
or Pipeline.Workspace
.
Variable type | Variable | Description | Example |
---|---|---|---|
Agent | Agent.BuildDirectory | The local path on the agent where all folders for a given build pipeline are created | D:\..\agent\_work\1 |
Agent | Agent.HomeDirectory | The directory the agent is installed into | C:\agent |
Agent | Agent.TempDirectory | A temporary folder that is cleaned after each pipeline job | D:\..\agent\_work\_temp |
Agent | Agent.ToolsDirectory | The directory used by tasks such as Node Tool Installer and Use Python Version to switch between multiple versions of a tool | D:\..\agent\_work\_tool |
Agent | Agent.WorkFolder | The working directory for agent | c:\agent_work |
Build | Build.SourcesDirectory | The local path on the agent where your source code files are downloaded. | c:\agent_work\1\s |
Build | Build.ArtifactStagingDirectory | The local path on the agent where any artifacts are copied to before being pushed to their destination. A typical way to use this folder is to publish your build artifacts with the Copy files and Publish build artifacts tasks | c:\agent_work\1\a |
Build | Build.StagingDirectory | The local path on the agent where any artifacts are copied to before being pushed to their destination. | c:\agent_work\1\a |
Build | Build.BinariesDirectory | The local path on the agent you can use as an output folder for compiled binaries | c:\agent_work\1\b |
Build | Build.Repository.LocalPath | The local path on the agent where your source code files are downloaded. | c:\agent_work\1\s |
Build | Common.TestResultsDirectory | The local path on the agent where the test results are created. | c:\agent_work\1\TestResults |
Pipeline | Pipeline.Workspace | The Workspace directory for a particular pipeline | /home/vsts/work/1 |
System | System.DefaultWorkingDirectory | The local path on the agent where your source code files are downloaded. | c:\agent_work\1\s |
Upvotes: 7
Reputation: 28086
You can check this document:
So for Linux its default location /home/<username>/Downloads
.
I do the test in Microsoft hosted agent-window2019
with test C# code(Hint from Daniel!) like:
static void Main(string[] args)
{
string FILEURI = "https://www.nuget.org/api/v2/package/Cauldron.Newton/2.0.0";
System.Diagnostics.Process prozess = new System.Diagnostics.Process();
prozess.StartInfo.FileName = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
prozess.StartInfo.Arguments = "--download " + FILEURI;
prozess.Start();
Console.WriteLine("Test starts.");
}
And then I use command like dir c:\users\VssAdministrator\cauldron.newton.2.0.0.nupkg /s /b
to find the location of downloaded file: cauldron.newton.2.0.0.nupkg
.
Then i confirmed the default download location of Chrome is still C:/Users/{user}/Downloads
, same as using self-agent or downloading locally. (VssAdministrator is user when run windows hosted agent)
So I think Linux hosted agent should have similar behavior. You can try to find your file from /home/<username>/Downloads
folder. Hope it helps.
Upvotes: 1
Reputation: 886
When you install the agent, you specify the work directory. In pipeline tasks, you can find out exactly where within that directory files are staged with variables like $(Agent.BuildDirectory). This might not be the exact location you need, but I think it is in the right direction.
For a complete list of predefined variables, see here: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml
Upvotes: 3