【问题标题】:Azure Pipelines - Is there a way to view the folder structure?Azure Pipelines - 有没有办法查看文件夹结构?
【发布时间】:2020-07-27 14:46:24
【问题描述】:

我正在努力描绘 azure 管道的文件夹结构。我知道有一些隐式目录,例如:

  • $(System.DefaultWorkingDirectory)
  • $(Build.ArtifactStagingDirectory)

这两个文件夹都是池中可用的特定构建代理上的文件夹。

有没有办法查看文件夹结构并更好地了解内容的布局?

【问题讨论】:

标签: azure-devops azure-pipelines


【解决方案1】:

您可以使用CMD task在微软托管的windows代理中调用tree command来获取文件夹结构。

我的脚本:

echo "Structure of work folder of this pipeline:"
tree $(Agent.WorkFolder)\1 /f

echo "Build.ArtifactStagingDirectory:" 

echo "$(Build.ArtifactStagingDirectory)"

echo "Build.BinariesDirectory:" 

echo "$(Build.BinariesDirectory)"

echo "Build.SourcesDirectory:"

echo "$(Build.SourcesDirectory)"

结果:

$(Agent.WorkFolder)代表当前代理的工作文件夹,$(Agent.WorkFolder)\1代表当前管道的工作文件夹。(通常第一个管道会放在$(Agent.WorkFolder)\1,第二个会放在$(Agent.WorkFolder)\2...)

所以很明显,对于一个管道运行,默认情况下它有四个文件夹:a(工件文件夹)、b(二进制文件夹)、s(源文件夹)和 TestResults(测试结果文件夹)。 s 文件夹是下载源代码文件的位置。对于构建管道:$(Build.SourcesDirectory)$(Build.Repository.LocalPath)$(System.DefaultWorkingDirectory) 代表同一个文件夹。更多详情见predefined variables

【讨论】:

  • 这真的帮助我找出了我遇到的路径问题。谢谢!!!!!!
  • 这个答案很有帮助,但对于我的 RELEASE 管道,我发现我的文件夹树是 D:\A\r1 而不是 D:\A\1。所以我使用了命令“tree $(Agent.WorkFolder)\r1 /f”
  • 如果代理是基于 linux 的,这会起作用吗?
【解决方案2】:

另一种选择是将其添加到 YAML 管道中:

-powershell: Get-ChildItem -Path 'Insert root path' -recurse

它看起来像:

Get-ChildItem -Path C:\Test\*.txt -Recurse -Force

Directory: C:\Test\Logs\Adirectory

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/12/2019     16:16             20 Afile4.txt
-a-h--        2/12/2019     15:52             22 hiddenfile.txt
-a----        2/13/2019     13:26             20 LogFile4.txt

    Directory: C:\Test\Logs\Backup

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/12/2019     16:16             20 ATextFile.txt
-a----        2/12/2019     15:50             20 LogFile3.txt

    Directory: C:\Test\Logs

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/12/2019     16:16             20 Afile.txt
-a-h--        2/12/2019     15:52             22 hiddenfile.txt
-a----        2/13/2019     13:26             20 LogFile1.txt

    Directory: C:\Test

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----        2/13/2019     08:55             26 anotherfile.txt
-a----        2/12/2019     15:40         118014 Command.txt
-a-h--        2/12/2019     15:52             22 hiddenfile.txt
-ar---        2/12/2019     14:31             27 ReadOnlyFile.txt

这里是documentation on the Get-ChildItem command if you need more information

【讨论】:

    【解决方案3】:

    文档为您提供了文件夹结构的示例。如果这还不够,请添加运行 gci -rec -directory | select-object fullname 或类似的 PowerShell 步骤。

    【讨论】:

      【解决方案4】:

      看起来更像这样(Agent的工作目录):

      【讨论】:

      • 有没有办法在不运行自托管代理的情况下获得此视图?
      • 编写一个 Powershell 脚本来获取和打印所有文件夹
      • 查看运行内联 Powershell 任务时提供的答案。无论代理托管在哪里,这都应该有效。
      猜你喜欢
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      • 2022-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多