18

I want to delete artifacts in artifactory.I googled and found this link https://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API

Here the Delete build,using REST API,is what we are going for at the moment.Can any one give me a general idea how the command should look using curl command.Also in buildname what do i need to specify?

Franklin
  • 221
  • 1
  • 4
  • 9

2 Answers2

26

For deleting a single artifact or folder you should use the Delete Item API, for example

curl -uadmin:password -XDELETE http://localhost:8080/artifactory/libs-release-local/ch/qos/logback/logback-classic/0.9.9

Notice that you will need a user with delete permissions.
If all goes well you should expect a response with a 204 status and no content.

The delete API is intended for deleting build information and is relevant if you are using the Artifactory build integration.

Dror Bereznitsky
  • 20,048
  • 3
  • 48
  • 57
  • 1
    We are at Artifactory version 4.12.2. Assume i have 10 repositories and i want to keep only last 20 artifacts in 5 repositories and unlimited in other 5 repositories. How i may automatically delete artifacts older than 20 from only 5 repositories. I attempted to use plugin available from jfrog website, but seems like that will imply deletion rule for all repositories. thanks in advance. – user3232823 Mar 22 '17 at 00:19
  • 3
    @user3232823 I suggest opening a separate question for this. cannot really address it in a comment – Dror Bereznitsky Mar 22 '17 at 11:55
  • I received `HTTP/1.1 405 Method Not Allowed`. `Allow: OPTIONS, GET, HEAD, POST` – cowlinator Feb 02 '22 at 03:59
  • Put a space after "-u" and "-X" in order to work, i.e., ```curl -u admin:password -X DELETE ```. – tedyyu Mar 09 '23 at 03:12
  • I use this command but i got not found error. – Amirhossein Taheri Aug 23 '23 at 10:05
0

Nowadays there's a tool that can be used for it (note that I am a contributor to that tool):

https://github.com/devopshq/artifactory-cleanup

Assume i have 10 repositories and i want to keep only last 20 artifacts in 5 repositories and unlimited in other 5 repositories

The rule for 10 repositories would look like:

# artifactory-cleanup.yaml
artifactory-cleanup:
  server: https://repo.example.com/artifactory
  # $VAR is auto populated from environment variables
  user: $ARTIFACTORY_USERNAME
  password: $ARTIFACTORY_PASSWORD

  policies:
    - name: reponame
      rules:
        - rule: Repo
          name: "reponame"
        - rule: KeepLatestNFiles
          count: 20
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
  • 1
    When linking to a website, blog or repo to which you have affiliation, you **must explicitly disclose your involvement**. Otherwise, your post may be flagged as spam. – Adrian Mole Sep 10 '22 at 20:56
  • @AdrianMole hi, thank you for the note, didn't know that rule! Is there a special flag for it in SO or I just should have mentioned like "I've contributed in the tool"? – Aleksey Burov Sep 26 '22 at 07:06
  • Something like what I have just edited in will normally suffice. I don't actually think you *are* a spammer, but [this article](https://stackoverflow.com/help/promotion) may be of some help. – Adrian Mole Sep 26 '22 at 07:12
  • @AdrianMole thank you for your work and the advice, appreciate it! I'm not a spammer, rather a newbie, but we behave the same sometimes... – Aleksey Burov Sep 26 '22 at 07:21