user26396173
user26396173

Reputation: 1

Is there a way to delete multiple folders in Azure DevOps without having to commit it 1-by-1?

So, without cloning the repo to a local machine and deleting them there and then committing, is there a way to delete multiple folders without it prompting me to commit these changes one by one?

Haven't been able to find a workaround

Upvotes: 0

Views: 128

Answers (1)

Miao Tian-MSFT
Miao Tian-MSFT

Reputation: 5567

Without cloning the repo to a local machine and deleting them there and then committing, is there a way to delete multiple folders without it prompting me to commit these changes one by one?

From the web interface, we can only delete the folders and commit the change one by one.

As a workaround, you can set up a pipeline to run the git command to delete the folders in your required branch and commit then in one commit.

Here is the sample YAML:

trigger:
- none

pool:
  vmImage: 'ubuntu-latest'

steps:
- checkout: self
  persistCredentials: true

- script: |
    git config --global user.email "[email protected]"
    git config --global user.name "Your Name"
    git fetch
    git checkout test
    rm -rf folder1 TestProject/folder2 TestProject/folder/folder3 
    git add -A
    git commit -m "Remove specific folders"
    git push origin test
  displayName: 'Delete  folders'

In the sample, I deleted the folder1, TestProject/folder2 and TestProject/folder/folder3 in the test branch. You can replace the folder paths and the branch name as you need.

Test result:

test result

Please noted that you should give your build service account the Contribute permission to perform this action.

permission

Otherwise, you may get this error: TF401027: You need the Git 'GenericContribute' permission to perform this action. Details: identity 'Build\xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', scope 'repository'.

There are two kinds of the build service account, one is project level named {Project Name} Build Service ({Org Name}), another is the organization level named Project Collection Build Service ({OrgName}). You can confirm your build service account referring the document or just search the ID from the error message to find the build service account.

search Id

Upvotes: 0

Related Questions