7

I have the following pipeline structure:

Job A --> Generate build files
Parallel:
  Job B --> Uses the build files
  Job C --> Uses the build files
Job D --> Publishes the build files
Job E --> Release
On finish, I want to delete the build files completely

I'm not convinced of using artifacts (because of the time taken for upload/download) but it is what I seem to need to use in order to use files across jobs

At the end of the pipeline, I don't really need to keep the build files (AKA artifacts), so how can I just simply delete them on pipeline finish?

I am using azure-pipelines.yml.

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
Dom
  • 580
  • 4
  • 26
  • Would challenge as to why? If wanting to remove them this goes against design. Won't be able to redeploy the artifact built at the initial release time which makes rolling back changes harder. – DreadedFrost Jul 06 '21 at 14:19
  • 1
    @DreadedFrost: Cuz if we need to redeploy, a simple re-run and rebuild the artifacts would make more sense. Keeping artifacts for years, months or even days that barely used and rollbacks happen on an extreme rare occasions to barely never. So in our expertise of our environment, we would challenge why keep the redundant artifacts? – Dom Jul 07 '21 at 07:54
  • @DreadedFrost: We also have tests on the container that runs the application before swapping. Furthermore, our rollbacks happen on docker image rather than using "artifacts" – Dom Jul 07 '21 at 08:00
  • This is not a good practice as it breaks the audit trail related to what, how, and why code is deployed. Understand what you are saying with containers. If worried about what is published this can be filtered in the publish pipeline artifact task. As mentioned retention policy is a way to minimize how long the artifacts are around for. – DreadedFrost Jul 07 '21 at 13:26
  • @DreadedFrost, what you are suggesting is irrelevant and not needed. I hope if anyone can suggest an alternative. Thanks for your help. – Dom Jul 07 '21 at 15:19

2 Answers2

4

As far I know there is no direct way of achieving this as there is not task for that, now Azure CLI command, nor Azure Rest API endpoint. What you can do here is to change retention policy and limit it via this:

enter image description here

Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
1

The proper method is the one mentioned in @Krzysztof 's post. However, if the OP really needs artifacts deleted immediately, rather than waiting one day, it could be accomplished with a Command Line task at the end of the pipeline.

Set the Working Directory to the location the artifacts are dropped in, and have it run this:

del /s /q *.* 2>NUL
rmdir /s /q "./" 2>NUL
exit 0

enter image description here

Azure Devops has had issues with properly over-writing artifacts in the past for me, so I use that code to clean up the directory prior to publishing a new artifact.

Jereme
  • 630
  • 6
  • 18
  • I wish we had this answer long time ago, we ditched azure devops and azure repo due to this. Microsoft charges per GB usage and because of tons of daily commits, we were paying for storage that we simply didn't need. Thanks Jereme. – Dom Jul 14 '22 at 03:58