【问题标题】:Azure DevOps - During the build pipeline run, what is the path where the Agent downloads the files locally?Azure DevOps - 在构建管道运行期间,代理在本地下载文件的路径是什么?
【发布时间】:2022-02-04 20:49:45
【问题描述】:

我们正在使用 Microsoft 托管代理来为我们的应用程序的自动化测试场景运行构建管道。我们想要实现的是,通过我们的自动化程序,下载文件(从无头 chrome 浏览器),然后导航到下载文件的路径并打开它。

如何在代理中找到下载文件的路径?

【问题讨论】:

  • 可以指定下载路径吗?
  • 不幸的是,这是一个将文件下载到默认目录的现有 Web 应用程序 - 对于 Windows 操作系统,它是“C:/Users/{user}/Downloads”。虽然这是一个 Linux 操作系统,但我不知道该默认位置。
  • 好吧,默认目录是什么?如果您知道目录 - 只需使用它。不过,我认为您无法在代理上使用它

标签: azure-devops azure-pipelines azure-pipelines-yaml


【解决方案1】:

安装代理时,您指定工作目录。在管道任务中,您可以使用 $(Agent.BuildDirectory) 等变量准确了解该目录中文件的暂存位置。这可能不是您需要的确切位置,但我认为它的方向是正确的。

有关预定义变量的完整列表,请参见此处:https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml

【讨论】:

  • 使用 ADO/VSTS/TFS 几年后 - 选择像 $(Agent.BuildDirectory) 或 $(Agent.SourceDirectory) 这样的预定义变量来定位脚本绝对是最佳实践。它让生活变得更加轻松,而且我过去没有这样做过,并且代理池更新破坏了我的脚本,因为位置发生了变化 - 这些变量会随着更新而移动。跨度>
【解决方案2】:

您可以查看this document:

所以对于 Linux,它的默认位置是 /home/<username>/Downloads

我在Microsoft hosted agent-window2019 中使用测试C# 代码(来自Daniel! 的提示)进行测试,例如:

        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.");
        }

然后我使用dir c:\users\VssAdministrator\cauldron.newton.2.0.0.nupkg /s /b 之类的命令来查找下载文件的位置:cauldron.newton.2.0.0.nupkg

然后我确认Chrome的默认下载位置还是C:/Users/{user}/Downloads,和使用自代理或者本地下载一样。 (运行 windows 托管代理时,VssAdministrator 是用户)

所以我认为 Linux 托管代理应该有类似的行为。您可以尝试从/home/<username>/Downloads 文件夹中找到您的文件。希望对您有所帮助。

【讨论】:

    【解决方案3】:

    official doc link快速编译与构建Linux和Windows自托管代理的路径相关的预定义变量列表。

    您正在寻找的是Agent.BuildDirectoryPipeline.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

    【讨论】:

      猜你喜欢
      • 2019-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 2020-01-01
      • 2020-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多