I'm trying to retrieve the latest version of a artifact from artifactory, but there is a file "maven-metadata.xml" in the target directory that is always being returned.
Is there a way for the request to exclude the file? My current request looks as follows:
"https://artifactory/api/storage/pathtodirectory?lastModified"
This returns the maven-metadata.xml file, I tried modifying the request to:
"https://artifactory/api/storage/pathtodirectory?lastModified?archiveType!=xml"
But that didn't exclude the file.
You have the option of retrieving the latest artifact which was modified, while also excluding patterns of files, using JFrog CLI.
Here's how you do it:
jfrog rt s repo-name/path/to/directory/ --sort-by modified --sort-order desc --limit 1 --exclusions "*maven-metadata.xml"
Notice that the source path argument ends with a slash (...directory/), to indicate that yuo wish to retrieve the content of the directory folder in Artifactory.
You can modify the source path argument and also the value of the --exclusions option to include wildcards, and also change the value of the --limit option to return the X last modified artifacts.
Once you're satisfied with the output, and you want to download the artifact, simply replace jfrog rt s with jfrog rt dl.
Related
I have artifacts in JFrog.
Example:
https://test.com/artifactory/users/data-config/1.0.0/user.json
https://test.com/artifactory/users/data-config/1.0.1/user.json
https://test.com/artifactory/users/data-config/2.0.0/user.json
Is there a way I can download the latest version using curl? Like in this case it will be
https://test.com/artifactory/users/data-config/2.0.0/user.json
Considering your comment that the files are not maven based, I assume it is deployed to a generic repository and irrespective of the file type, the only way to resolve the file via direct cURL is using the following command.
curl -u<USERNAME>:<PASSWORD> -O "http://<HOSTNAME>:<PORT>/artifactory/generic-repository/<TARGET_FILE_PATH>"
So, the target path name should be given completely when it is being resolved via direct download (API). i.e., The complete target file name manually.
However, for other package types such as a maven release or a snapshot, the available options are described here.
What are a few other additional options available?
Artifact Latest Version Search Based on Layout
, Artifact Latest Version Search Based on Properties
I need to write an yaml script to get the most recent artifact from artifact repository and store it in a windows server.
Repository Browser Structure would be like the below
Name of the Repo - Generic_App
TEST_APP is a folder inside the repo.
Generic_App->TEST_APP->1->TEST_APP-1.ZIP
Generic_App->TEST_APP->2->TEST_APP-2.ZIP
Generic_App->TEST_APP->3->TEST_APP-3.ZIP
Can you help me with the script to download TEST_APP-3.ZIP
You requested for a yaml script. I guess it'll be easy for you to embed the following command in any script you may be using.
The following JFrog CLI command downloads the latest file from Artifactory, which matches your requirements. The command will look for the newest file created, which path and name matches the following pattern (notice the wildcard in the file name pattern) -
Generic_App/TEST_APP/TEST_APP-*.ZIP
jfrog rt dl "Generic_App/TEST_APP/TEST_APP-*.ZIP" --sort-by created --sort-order desc --limit 1 --url "<artifactory url>" --user "<artifactory username>" --password "<artifactory password>"
Note: In most cases, the Artifactory URL ends with /artifactory
If the machine which runs the script doesn't have JFrog CLI installed, here's how you can install it - https://jfrog.com/getcli/
I use mvn deploy:deploy-file to publish snapshots to nexus.
The snapshot is created with timestamp in the following format xxxx-1.0.0.0-20171206.163242.jar
In addition the maven-metadata.xml file is updated with the name of the last snapshot.
Sometimes there is a race condition between the timestamp of the file name in the metadata and the real file name.
for example the file name is xxxx-1.0.0.0-20171206.163242.jar and in metadata it would be xxxx-1.0.0.0-20171206.163241.jar
I tried to use -DuniqueVersion=false in order to remove the timestamp but it seems that it does nothing and the filenames still contain timestamp
Any idea how to solve this issue?
Is it possible to upload a file into Nexus (Open Source Version) without having its filename changed? By change I mean where uploaded file does not take the format artifactId-version-classifier but just kept its original file name.
For example: if I were you upload a file called t01.jar to nexus with the groupId being computerScience, the artifactId being Assignment1, and the version number being 1.0, the uploaded file would have a new file name Assignment1-1.0.jar but I want the file to retain its name t01.jar.
Is it possible for me to retain the original file name?
No, if you are using a Maven repository format on a repository server it dictates the structure of that repository in terms of directory and filename.
This makes it deterministic to retrieve filenames based on the coordinates. If you want to have another filename just change the filename after you downloaded the file from the repo.
The same applies btw if you use an Ivy repository or any other repository. They have a set naming convention and structure. For ivy it can be configured but once configured the same convention applies to all files and it is also using GAV coordinates for naming files and folders.
Again.. the main thing is ... there is no reason to insist on a specific filename!
I have a zip archive artifact. I'm interested in downloading a single file from that artifact. I can't upload that file outside of the archive right now. The documentation says you download an archive like this
/repository/download/BUILD_TYPE_ID/BUILD_ID:id/ARTIFACT_PATH
So, my URL for that looks like this (and I need anonymous access, so you see the guest flag). And it works!
/repository/download/bt23/2253:id/mypackage.zip?guest=1
However, I want one single file from that artifact. And the docs are confusing on how to do that. They do not specify what replaces <zip or jar archive>. And I am not constructing the whole buildNumber or buildTypeId values properly.
/repository/archive/<zip or jar archive>/buildTypeId/BUILD_TYPE_ID/buildNumber/BUILD_NUMBER/index.html
I tried using zip and `.zip'. I tried filling in the build values directly, but it's much different from the working archive download URL.
/repository/archive/zip/buildTypeId/bt23/buildNumber/2253/myfile.txt?guest=1
Does anyone have working concrete example of the URL for a single file in an archive?
You need to replace <zip or jar archive> with relative path to your artifact. For example, if you want to retrieve file.txt from package.zip which is uploaded under dist directory in your build artifacts you need to use this url:
http://server/repository/archive/dist/package.zip/buildTypeId/bt23/buildNumber/2253/file.txt?guest=1
BTW, a new, more straightforward URL syntax will be available in TeamCity 7.0:
http://server/repository/download/bt23/2253/dist/package.zip!file.txt?guest=1
Old URLs will be supported too.