Delete Rest API specifying time period without using Artifact Cleanup Plugin and JFrog CLI - artifactory

I'm quite new with Artifactory, and I was trying to delete some artifacts to make a sort of clean up of the old artifacts I don't use anymore.
I've found some solutions:
Using Artifact Cleanup Plugin, but I can't use it, as I'm not an Admin user in Artifactory and I can't install it. Plus, it isn't already installed, so I can't use it
Delete operation through JFrog CLI. I can't use it, as it isn't installed and I can't install it by myself
The only thing I can do by myself is calling the JFrog Rest Api through curl as documented in the following page:
https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API?_gl=1*1q2oqbv*_ga*MTc5MDMxODk1Mi4xNjU2MzIxMjEx*_ga_SQ1NR9VTFJ*MTY2NzU4MDA0MS41NS4xLjE2Njc1ODAwODAuMjEuMC4w#ArtifactoryRESTAPI-DeleteBuilds
My question is if I could use, without plugins or the JFrog CLI, any sort of parameter in my DELETE request in which I can specify, for example, an amount of "months" or "days" to filter what I would like to delete from Artifactory.
Actually I'm using this string, which only deletes that specified "folder":
curl -u artifactory_user:artifactory_password -X DELETE https://website/artifactory/repositoryname/folder
Do these parameters exist?
Can you provide me an example of how could I integrate them in my request?

You don't need to install JFrog CLI on JFrog server.
You can install on your local computer bt referring to this link.
Validate if cli is installed by running the command 'jfrog' from your command prompt. You need to authenticate to Artifactory from CLI.
Create a file with a name input.spec with the below contents.
{
"files": [
{
"aql": {
"items.find": {
"repo": "test-repository",
"$or": [
{
"$and": [
{
"modified": { "$lt": "2022-10-01T21:26:52.000Z"}
}
]
}
]
}
}
}
]
}
Run the below command to verify if this is resulting in correct file list from the repository that we want.
jfrog rt s --spec input.spec
This gives you the list of the files that are uploaded to the repository test-repository, before the date 2022-10-01.
Run the below query to actually delete the above listed files.
jfrog.exe rt del --spec input.spec
This will delete the artifacts that are older than 2022-10-01 from the repository test-repository. You can modify the above input.spec file according to your need and run the same command.

Related

How do I delete a specific Jfrog build with the cli (and its corresponding artifact)

I'm confused about how to perform this operation, it almost seems like it's not supported. Looking at the docs I see no examples for deleting a specific build version: https://www.jfrog.com/confluence/display/CLI/CLI+for+JFrog+Artifactory#CLIforJFrogArtifactory-DiscardingOldBuildsfromArtifactory
I use build discarding now, but that's not what this is. I want to remove a specific build version and its corresponding artifact, not use --max-days or --max-builds. How is this possible? I want to delete the build AND the artifact.
I use Jfrog to host an internal helm repo, helm has no built-in command to delete a chart from a remote repo.
For deleting a specific artifact of a build using jfrog cli run
jfrog rt delete --build build-name/build-number
Parse --dry-run to know which artifacts would have been deleted.
More info on CLIforJFrogArtifactory-DeletingFile.

Jfrog Search & Delete Not Working

I am trying to search for all files that are in my repo on Artifactory. I have Go installed, and am using Jfrog to query the search using:
jfrog rt s https://URL/artifactory/generic-sgca/
Which returns:
[Info] Searching artifacts...
[Info] Found 0 artifacts.
[]
Why is it not returning all folders in this repo? I believe my config is setup correctly too.
You are not supposed to be specifying the https://url/artifactory when using search function in the CLI.
you can check the CLI's search help using jfrog rt s -h and you'll see that the usage is:
jfrog rt s [command options] <search pattern>
where search pattern should:
Specifies the search path in Artifactory, in the following format: <repository name>/<repository path>
The URL is actually a command option --url=http://myurl:myport/artifactory which you can leave out if you use jfrog rt config to set the Artifactory server details before you run the search command.
You can read more and find some snippet example here

Cleanup old artifacts from Jfrog artifactory OSS

I'm using Jfrog artifactory OSS version 5. I can see my snapshot repository is too huge and I want to remove unwanted artifacts from snapshot repository.
I want to remove all artifacts which were not downloaded during last 6 months.
I tried below method, but its not working seems because of I'm using OSS version.
curl -X POST -v -u user:'password' "http://<my artifactory url>/artifactory/api/execute/cleanup?params=months=6|repos=snapshots|dryRun|paceTimeMS=2000"
Is there any other way that I can perform my task and if somebody can help me to do this, it would be really appreciated.
Thank You
You can use JFrog's CLI to delete items based on AQL queries.
For example, you can use an AQL query like:
items.find({"created" : {"$before" : "6mo"}})
To find all items that were created over 6 month ago.
You can then use your AQL as part of a spec file for deleting items and artifacts, using the JFrog CLI.
To read more about the AQL Time Operators
To read more about CLI and File Specs
items.find (
{
"repo":"snapshots",
"stat.downloads":{"$eq":null}
}
)
This will search for file which have not been downloaded ever, under repository name "snapshots"

jfrog rest api: Deploying jars with group id and Artifact id

I have been trying to upload my application specific JARs to the JFrog Artifactory using the rest API but couldn't find any methods to include the group id and the artifact id like maven does.
This command does deploy the jar to repository but without the groupId and artifactId;
curl -u username:password -X PUT "http://xx.xx.xxx.xx:8081/artifactory/libs-release-local/mail-1.4.3.jar" -T mail-1.4.3.jar
Are there any way that I could mention the Group id and Artifact Id while uploading the JARS to artifactory using Jfrog Rest API ?
There is nothing that will do it automatically for you, but you can definitely specify a full path that includes the groupId, artifactId and version of your artifact exactly like Maven would, i.e:
curl -u username:password -T mail-1.4.3.jar "http://xx.xx.xxx.xx:8081/artifactory/libs-release-local/org/someOrg/mail/1.4.3/mail-1.4.3.jar"
(p.s - you don't need to specify -XPUT if you specify -T)
BTW - unlike the REST API, the Artifactory UI does actually have the ability to fill in the full maven coordinates for you during upload. Have a look here:
https://www.jfrog.com/confluence/display/RTF/Deploying+Artifacts#DeployingArtifacts-DeployingMavenArtifacts

How to publish builds to Artifactory from GitLab CI?

I am looking for an easy and clean way to publish artefacts build with GitLab CI onto Artifactory.
I was able to spot https://gitlab.com/gitlab-org/omnibus/blob/af8af9552966348a15dc1bf488efb29a8ca27111/lib/omnibus/publishers/artifactory_publisher.rb but I wasnt able to find any documentation regarding how I am supposed to configure it to make it work.
Note: I am looking for a gitlab_ci.yaml approach, not as in implementing it externally.
At a basic level, this can be done with the JFrog CLI tools. Unless you want to embed configuration in your .gitlab-ci.yml (I don't) you will first need to run (on your runner):
jfrog rt c
This will prompt for your Artifactory URL and an API key by default. After entering these items, you'll find ~/.jfrog/jfrog-cli.conf containing JSON like so:
{
"artifactory": {
"url": "http://artifactory.localdomain:8081/artifactory/",
"apiKey": "AKCp2V77EgrbwK8NB8z3LdvCkeBPq2axeF3MeVK1GFYhbeN5cfaWf8xJXLKkuqTCs5obpzxzu"
}
}
You can copy this file to the GitLab runner's home directory - in my case, /home/gitlab-runner/.jfrog/jfrog-cli.conf
Once that is done, the runner will authenticate with Artifactory using that configuration. There are a bunch of other possibilities for authentication if you don't want to use API keys - check the JFrog CLI docs.
Before moving on, make sure the 'jfrog' executable is in a known location, with execute permissions for the gitlab-runner user. From here you can call the utility within your .gitlab-ci.yml - here is a minimal example for a node.js app that will pass the Git tag as the artifact version:
stages:
- build-package
build-package:
stage: build-package
script:
- npm install
- tar -czf test-project.tar.gz *
- /usr/local/bin/jfrog rt u --build-name="Test Project" --build-number="${CI_BUILD_TAG}" test-project.tar.gz test-repo
If you're building with maven this is how I managed to do mine:
Note: you need to have your artifactory credentials (user and pass) ready.
Create a master password and generate an encrypted password from it. The procedure on how to create a masterpassword can be found here
In your pipeline settings in gitlab, create 2 secret variables, one for the username and the other for your encrypted password.
Update or create a settings.xml file in .m2 directory for maven builds. Your settings.xml should look like this:
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>central</id>
<username>${env.ARTIFACTORY_USER}</username>
<password>${env.ENCRYPTED_PASS}</password>
</server>
</servers>
</settings>
In your .gitlab-ci.yml file, you need to use this settings.xml like this:
image: maven:latest
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
- target/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS compile
and that's it. This should work. You can visit here for more about how to use artifactory with maven
I know this doesn't exactly answer your question, but I got to this question from a related search, so I thought it might be relevant to others too:
I ended up using an mvn deploy job that was bound to the deploy stage for gitlab.
Here is the relevant job portion:
deploy:jdk8:
stage: test
script:
- 'mvn $MAVEN_CLI_OPTS deploy site site:stage'
only:
- master
# Archive up the built documentation site.
artifacts:
paths:
- target/staging
image: maven:3.3.9-jdk-8

Resources