microsoft / azure-pipelines-task-lib

Libraries for writing VSTS and TFS build tasks
https://aka.ms/tfbuild
MIT License
412 stars 271 forks source link

rmRF on Windows fails due to 'path is too long', cannot delete published build artifacts #721

Closed japj closed 3 years ago

japj commented 3 years ago

Environment

azure-pipelines-task-lib version: 2.9.3 (as part of DeleteFiles 1.166.2) Related to https://github.com/microsoft/azure-pipelines-tasks/issues/14459

Issue Description

rmRF fails to delete published build artifacts

Expected behaviour

Since the files were published by using the Publishing Build Artifacts task we expect the files to also be correctly deleted when manually deleting the build from AzureDevOps (or when cleaning up happens due to the build retention being triggered).

Actual behaviour

Build Artifacts published to a UNC fileshare failed to be deleted by the DeleteFiles/rmRF logic due to the "rd" command failing. I manually confirmed on the buildserver that the rd command (https://github.com/microsoft/azure-pipelines-task-lib/blob/master/node/task.ts#L1171) fails with The path xxxxx is too long (the reported path is actually 263 characters long).

Steps to reproduce

  1. setup a build definition that publishes artifacts to a unc fileshare, where content has a long path
  2. queue a build and see that artifacts were correctly published
  3. manually delete the build (in AzureDevOps Server)
  4. see that not all content is removed from the fileshare
  5. agent worker logging contains Step result: Failed for the Delete Artifacts job "DeleteFiles" step
japj commented 3 years ago

@damccorm the PublishBuildArtifacts task seems to use robocopy to copy the files to a fileshare, so that seems to work correctly for long path content.

Would it be an option to use robocopy to "delete" the files instead of using rd/? (since rd seems to fail in such case)

japj commented 3 years ago

Workaround is to: