I'm trying to setup the DeleteFiles task to delete all DLL files that start with 'ab' except for a specific one.
For example if I have:
abfile.one.dll
abfile.two.dll
abotherfile.dll
System.Stuff.dll (there are 20-30 of these that need to be included)
abdontdeleteme.dll
I expect the resulting files:
System.Stuff.dll
abdontdeleteme.dll
I've tried a bunch of different configs but none have worked. The config that I thought made the most sense was:
- task: DeleteFiles@1
displayName: 'Cleanup Assemblies'
inputs:
sourceFolder: ${{parameters.theDirectoryToCleanup}}
contents: ab*.dll !abdontdeleteme.dll
This config does nothing. Setting System.Debug to true and looking at the output I see:
##[debug]pattern: 'D:/a/1/b/api/bin/ab*.dll !abdontdeleteme.dll'
##[debug]applying include pattern against original list
##[debug]0 matches
##[debug]0 final results
I also tried with just ab*.dll which worked but that deletes the one DLL I care about. Is there a way to exclude a specific file from the match list?
Edit
As per a suggestion in the comments I tried the following to the same results (no files were deleted):
- task: DeleteFiles@1
displayName: 'Cleanup Assemblies'
inputs:
sourceFolder: ${{parameters.theDirectoryToCleanup}}
contents:
ab*.dll
!abdontdeleteme.dll
Edit 2
I tried the following:
- task: DeleteFiles@1
displayName: 'Cleanup Assemblies'
inputs:
sourceFolder: ${{parameters.theDirectoryToCleanup}}
contents: |
ab*.dll
!(abdontdeleteme.dll)
This deletes everything except 'abdontdeleteme.dl'
- task: DeleteFiles@1
displayName: 'Cleanup Assemblies'
inputs:
sourceFolder: ${{parameters.theDirectoryToCleanup}}
contents:
ab*.dll
!(abdontdeleteme.dll)
This again matches to nothing and nothing gets deleted.
After a lot of frustration I gave up and used Powershell because it can do what I want. It's not the best solution but it works as some of the other steps require a Windows image anyways. The code that worked is:
- task: PowerShell@2
displayName: "Cleanup Web Services"
inputs:
targetType: 'inline'
script: Remove-Item "path\to\my\stuff\*" -Include "ab*.dll" -Exclude "abdontdeleteme.dll"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With