Reputation: 2427
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.
Upvotes: 3
Views: 2817
Reputation: 2427
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"
Upvotes: 4
Reputation: 19016
Based on the tasks compile logic, you's better convert your syntax direction, to tell the system what files you need to keep.
So, just try !(System.Stuff.dll|abdontdeleteme.dll)
in task definition:
- task: DeleteFiles@1
displayName: 'Delete files'
inputs:
SourceFolder: ${{parameters.theDirectoryToCleanup}}
Contents: !(System.Stuff.dll|abdontdeleteme.dll)
From the build log, you could easily found that when you specify multiple matching expressions in different line:
ab*.dll
!(abdontdeleteme.dll)
All of them are compiled them separately into source path/ab*.dll
, source path/!(abdontdeleteme.dll)
. But currently, tasks cannot solve them both at the same time.
Meanwhile, if you specify those 2 expression into one line, the system identified them as source path/ab*.dll !abdontdeleteme.dll
. Obviously, delete files could not be succeed.
Upvotes: 0