Dom
Dom

Reputation: 648

How to delete Azure pipeline artifacts after it's finished?

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.

Upvotes: 9

Views: 14283

Answers (2)

Jereme
Jereme

Reputation: 690

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.

Upvotes: 3

Krzysztof Madej
Krzysztof Madej

Reputation: 40939

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

Upvotes: 4

Related Questions