-1

In azure.yml script, I would like to recursively search for a folder that ends with _test in $(System.DefaultWorkingDirectory)

So far, tried out

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

and

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

However, both patterns are not working.

Is it possible to do recursive search for a folder in $(System.DefaultWorkingDirectory)?

Can you please suggest a suitable method to search for folders ending with _test in $(System.DefaultWorkingDirectory)?

Thank you!

Yamuna
  • 71
  • 1
  • 2
  • 13

1 Answers1

0

If you want to search for folders ending with _test in $(System.DefaultWorkingDirectory) in azure.yml script, please try the following yaml sample.

pool:
  vmImage: ubuntu-latest

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

Update>> Microsoft-hosted Ubuntu agent has installed PowerShell tools, so PowerShell is available in it. If you prefer to use Bash script, this command find $(System.DefaultWorkingDirectory) -name "**_test" -type d will output the target folders path.

Please note that there might be multiple folders, you could use following script to assign the result to variable.

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

Or you could assign the result to array by reference to this thread.

- bash: |
    readarray -d '' result_array < <(find $(System.DefaultWorkingDirectory) -name "**_test" -type d)
    echo "$result_array"
Edward Han-MSFT
  • 2,879
  • 1
  • 4
  • 9
  • Thank you the suggestion! Powershell is not available in the hosted agent. Hence I am getting "command not found" error. – Yamuna Mar 31 '21 at 05:19
  • I am planning to use bash command "find" to verify if _test folder is present. I tried the following but it doesn't seem to work UNIT_TEST=$(find . -name "*_test") echo "##vso[task.setvariable variable=UNIT_TEST]$UNIT_TEST" Please let me know how to get output of bash in a variable.Thank you! – Yamuna Mar 31 '21 at 05:27
  • Hi Yamuna, I have updated my answer for your reference. Please note that the result cannot be assigned to variable via ```echo "##vso[task.setvariable variable=UNIT_TEST]$UNIT_TEST"``` because they are different data structure. You could try to iterate through the array to assign its elements to different variables. – Edward Han-MSFT Mar 31 '21 at 07:01
  • Hi @Edward Han-MSFT, result=$(find $(System.DefaultWorkingDirectory) -name "**_test" -type d) worked for me. Thank you for the support! – Yamuna Apr 05 '21 at 10:00