Jfrog Search & Delete Not Working - artifactory

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

Related

could not download symlink from artifactory using jfrog cli

jfrog rt dl --symlinks=true generic-local/latest.tgz
Getting "Incorrect Usage".
jfrog cli version 1.18.0.
Is it possible to download a symlink data from jfrog CLI?
In jfrog cli, --symlink is a parameter used for preserving the soft links structure in Artifactory during the upload.
So for downloading you can use the following command
jfrog rt dl generic-local/latest.tgz
In addition, when downloading symlinks stored in Artifactory, the CLI can verify that the file to which the symlink points actually exists and that it has the correct SHA1 checksum. To add this validation, you should use the --validate-symlinks option with the download command.

Artifactory CLI sort and limit the number of artifacts

Is there any way to sort and limit the number of artifacts while downloading artifacts using CLI for Jfrog Artifactory?
Example: if we have 100 artifacts in a single repo and I want to download only top 5 artifacts.
Thanks!
Jfrog CLI currently does not support SORT and LIMIT.
This is actually a roadmap item currently evaluated for Q4 17.
You can follow this Github issue to stay up-to-date with the implementation efforts.
for the meantime, you can use AQL with SORT and LIMIT over the JFrog REST API.
For example, the below AQL query Sorts by Descending creation dates and Limits the returned number of items to 5.
it can be used as the body of a simple POST method:
items.find(
{
"repo":"my-repo-local"
}
).sort({"$desc" : ["created"]}).limit(5)
HTH,
Or
You can not limit the download to X number of artifacts using Jfrog Cli but there are 3 ways to "limit" your artifact donwload using Jfrog Cli.
These options are:
If you need only a specift artifact:
jfrog rt dl your-artifactory-local-repo/YOUR-ARTIFACT-NAME.EXTENSION
This example download the artifact named YOUR-ARTIFACT-NAME.EXTENSION from "your-artifactory-local-repo" to your local folder.
If you need all the artifact in a folder:
jfrog rt dl your-artifactory-local-repo/YOUR-ARTIFACT-FOLDER/ YOUR-LOCAL-FOLDER/
This example download all the artifacts from "your-artifactory-local-repo/YOUR-ARTIFACT-FOLDER/" to YOUR-LOCAL-FOLDER/
Using a regular expresion (best way):
Example 3.1:
jfrog rt dl "your-artifactory-local-repo/*" YOUR-LOCAL-FOLDER/
This command also download all the artifacts from "your-artifactory-local-repo/YOUR-ARTIFACT-FOLDER/" to YOUR-LOCAL-FOLDER/
Example 3.2:
jfrog rt dl "your-artifactory-local-repo/*.EXTENSION" YOUR-LOCAL-FOLDER/
This command also download all the .EXTENSION from "your-artifactory-local-repo/YOUR-ARTIFACT-FOLDER/" to YOUR-LOCAL-FOLDER/
Example 3.3:
jfrog rt dl "your-artifactory-local-repo/*SUBNAME.*" YOUR-LOCAL-FOLDER/
This command also download all the artifacts that ends with "SUBANME.*" from "your-artifactory-local-repo/YOUR-ARTIFACT-FOLDER/" to YOUR-LOCAL-FOLDER/
The best way is using regular expressions.

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

Is there a URL for the latest snapshot for an artifact in Artifactory?

I would like to make a permalink to the latest snapshot version of an artifact in Artifactory. If we are on 1.0-SNAPSHOT, I would like a URL that downloads the latest 1.0-SNAPSHOT JAR. I can find the latest artifact by locating the artifact on our server at http://hostname/artifactory/libs-snapshot/groupId/artifactId/1.0-SNAPSHOT/. Other than checking the timestamps, I can figure out which one if the latest by opening maven-metadata.xml and matching metadata/versioning/snapshot timestamp and buildNumber with a JAR in the same directory. This could be scripted, but ideally Artifactory already has a way to construct a permalink in this manner. Does Artifactory provide such a URL?
Doing the normal query for the entry with artifactId-1.0-SNAPSHOT.jar in the URL name should return automatically the latest snapshot.
See the doc here
One thing: This is base either on the latest creation date if no pom present, or latest creation of the pom if there are some. Mixing pom and non-pom deployment may results in strange results!
I tried using shell script and it worked for me.
Step1: Get an encrypted password for your user account by clicking on user name or create a common user. Go to using your secure password section in the following link
http://www.jfrog.com/confluence/display/RTF/Centrally+Secure+Passwords
Step 2: In your local machine create a temp folder and type this curl(may be wget for windows) command:
curl -o tmp/foo.jar --user <username>:<encrypted_password> <artifactory_url>/list/libs-snapshot-local/com/search/foo/1.0/foo-1.0-SNAPSHOT.JAR
Your foo.jar in tmp folder is latest version. If we dont give timestamp as like above, it will download latest artifact in that version. Hope this helps!
This might be helpful:
How to download the latest artifact from Artifactory repository?
Although there is no permalink ability in the free version of Artifactory, it can be scripted easily as you suggest. I have provided a quick script to do that in the referenced question.
Hope it helps.
Another portable option is to use the maven command line:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -DartifactId=[artifactId] -DgroupId=[groupId] -Dversion=[version] -Ddest=[dest file]
This works for me (no search API, just direct artifact URL):
curl -O -J --user <username>:<encrypted_password> http://hostname/artifactory/libs-snapshot/groupId/artifactId/1.0-SNAPSHOT/artifactId-1.0-SNAPSHOT.jar
Basically using 1.0-SNAPSHOT in the artifact name downloads the latest version of 1.0-SNAPSHOT snapshot.

Resources