首页 > 解决方案 > Azure yml - 在 $(System.DefaultWorkingDirectory) 中递归搜索文件夹

问题描述

在 azure.yml 脚本中,我想递归搜索以$(System.DefaultWorkingDirectory)中的 _test 结尾的文件夹

到目前为止,尝试过

[ -d "**/$(System.DefaultWorkingDirectory)/**/?(*_test)" ]

 [ -d "$(System.DefaultWorkingDirectory)/**/*_test" ]

但是,这两种模式都不起作用。

是否可以递归搜索 $(System.DefaultWorkingDirectory) 中的文件夹?

您能否建议一种合适的方法来搜索$(System.DefaultWorkingDirectory)中以 _test 结尾的文件夹?

谢谢!

标签: azureazure-devopsazure-yaml-pipelines

解决方案


如果要在 azure.yml 脚本中搜索 $(System.DefaultWorkingDirectory) 中以 _test 结尾的文件夹,请尝试以下 yaml 示例。

pool:
  vmImage: ubuntu-latest

steps:
- pwsh: Get-ChildItem -Path $(System.DefaultWorkingDirectory) -Recurse -Directory -Name -Include "**_test"

更新>> Microsoft 托管的 Ubuntu 代理已安装 PowerShell 工具,因此可以使用 PowerShell。如果您更喜欢使用 Bash 脚本,此命令find $(System.DefaultWorkingDirectory) -name "**_test" -type d将输出目标文件夹路径。

请注意,可能有多个文件夹,您可以使用以下脚本将结果分配给变量。

- bash: |
    result=$(find $(System.DefaultWorkingDirectory) -name "**_test" -type d)
    echo "$result"

或者您可以通过引用此线程将结果分配给数组。

- bash: |
    readarray -d '' result_array < <(find $(System.DefaultWorkingDirectory) -name "**_test" -type d)
    echo "$result_array"

推荐阅读