Azure Pipelines - 有没有办法查看文件夹结构?

Cri*_* E. 13 azure-devops azure-pipelines

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

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

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

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

Dre*_*ost 23

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

- powershell: Get-ChildItem -Path 'Insert root path' -recurse
Run Code Online (Sandbox Code Playgroud)

它看起来像:

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
Run Code Online (Sandbox Code Playgroud)

如果您需要更多信息,请参阅有关 Get-ChildItem 命令的文档

  • 这不会在linux代理上写入文件名 (3认同)
  • 在我的 yaml 中,我想使用 powershell@2 任务(这不是为 yaml 格式化的,但你明白了): `- task: PowerShell@2 input: targetType: inline script: Get-ChildItem -Path '$(Agent. WorkFolder)\*.*' -recurse -force` (2认同)

Lan*_*SFT 19

您可以使用CMD 任务在 Microsoft 托管的 Windows 代理中调用tree 命令来获取文件夹结构。

我的脚本:

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)"
Run Code Online (Sandbox Code Playgroud)

结果:

在此处输入图片说明

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

所以很明显,对于一个管道运行,它默认有四个文件夹:a(工件文件夹)、b(二进制文件夹)、s(源文件夹)和 TestResults(测试结果文件夹)。该s文件夹是下载源代码文件的位置。对于构建流水线:$(Build.SourcesDirectory)$(Build.Repository.LocalPath)$(System.DefaultWorkingDirectory)表示相同的文件夹中。更多细节参见预定义变量

  • 这个答案非常有帮助,但对于我的 RELEASE 管道,我发现我的文件夹树是 D:\A\r1 而不是 D:\A\1。所以我使用命令“tree $(Agent.WorkFolder)\r1 /f” (3认同)
  • 这确实帮助我解决了我遇到的路径问题。谢谢你!!!!! (2认同)

Mik*_*ike 18

@LoLance 的答案非常适合 Windows 代理。对于 Linux 代理,语法略有不同(反转斜杠,并删除 /f 标志):

    - task: CmdLine@2
      inputs:
        script: |
          echo "Structure of work folder of this pipeline:"
          tree $(Agent.WorkFolder)/1

          echo "Build.ArtifactStagingDirectory:" 
          echo "$(Build.ArtifactStagingDirectory)"

          echo "Build.BinariesDirectory:" 
          echo "$(Build.BinariesDirectory)"

          echo "Build.SourcesDirectory:"
          echo "$(Build.SourcesDirectory)"
Run Code Online (Sandbox Code Playgroud)


sha*_*359 14

在此输入图像描述

来源:本博客的用户评论

请注意,根据您的环境,您的完整路径可能看起来有所不同。

例如:您的 Build.StagingDirectory 路径可能是c:\agent_work\1\a
/home/vsts/work/1/a/

这基于 Agent.BuildDirectory 或 Pipeline.Workspace 变量。(c:\agent_work\1 或 /home/vsts/work/1 或 /a/1 或类似的东西)

Azure 文档中的更多内容