Copy the latest artifact in the artifactory CURL - shell

i have repo of snapshots like this:
www.arifactoryrepo.com/maven-last-dev/com/api/2.3.5-SNAPSHOT
In the snapshot directory i have a lot of of zip files:
morad-2.3.5-20201207_291847218.zip
morad-2.3.5-20201107_291847218.zip
morad-2.3.5-20201007_291847218.zip
when i click on the link of:
www.arifactoryrepo.com/maven-last-dev/com/api/2.3.5-SNAPSHOT/morad-2.3.5-SNAPSHOT.zip
it downloads for me the latest snapshot (morad-2.3.5-20201207_291847218.zip)
I need to copy the latest one to another path, so i used this command:
curl -u <USER:PASS> -X post "www.arifactoryrepo.com/artifactory/api/copy/maven-last-dev/com/api/2.3.5-SNAPSHOT.zip?to=/another/path.
and i get error of "failed to copy" maybe because the link is redirected.
so, there is anyway to copy the latest artifact ?
Thanks,
Morad.

The copy REST API does not support the translation of Maven unique snapshots.
You can use the artifact latest version API in order to get the correct version and then use it for the copy API, for example:
VERSION=$(curl -uuser:pass "https://myrepo.jfrog.io/artifactory/api/search/latestVersion?g=com.api&a=morad&v=2.3.5-SNAPSHOT&repos=libs-snapshot-local")
curl -uuser:pass -XPOST "https://myrepo.jfrog.io/artifactory/api/copy/libs-snapshot-local/com/api/moard/2.3.5-SNAPSHOT/morad-$VERSION.zip?to=/libs-snapshot-local/copy/me"

Related

How to get latest artifact from artifactory?

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

How to download folder artifact from artifactory

I need download artifact level folder from artifactory on shell script. I have found some same topics but I not found solution. Please give me solution.
A tip for non PRO users:
Through the GUI go to the repository path (e.g. http://artifactory.mycompany.com:8081/artifactory/list/libs-release-local/path/to/my/folder/
Use the folder to recursively WGET the contents (e.g. wget -r --no-parent -nH --cut-dirs=4 --proxy=off http://artifactory.mycompany.com:8081/artifactory/list/libs-release-local/path/to/my/folder/)
When using the PRO version of Artifactory you can use this REST API for downloading a complete folder.

Unable to download snapshot artifacts using curl from bintray.com

I'm automating the deploy process of a project and one of the things that I'm struggling is to download from Bintray the latest snapshot version of a given maven artifact.
This https://bintray.com/docs/api/#_dynamic_download documentation states that you should use $latest variable but all tentatives gave me a 404 error. Following is a curl sample
curl -v -H 'X-Bintray-Package: main' -utmoreira2020:mytoken 'https://bintray.com/content/liferay/myrepo/com/liferay/myproject/distribution/$latest/distribution-$latest.lpkg'
Thanks in advance
Couple of things that can go wrong here:
The dynamic content is only available for a Pro package (i.e. in a repo that belongs to a Pro user or a Pro organization).
Curl treats $ as a special character, you need to escape it with \. Here's an example: curl -u jbaruch -L "https://api.bintray.com/content/jfrog-int/iot-generic-distribution/firmare-\$latest.bin?bt_package=arduino-jfrog-firmware"
You are trying to download a Maven unique snapshot. This won't work because the version in the path is referred to as SNAPSHOT, while the version in the file name is the timestamp of the build. You might want something like Aritfactory's [SNAPSHOT] token, but that won't happen, because Bintray is a service for distributing releases, not development time snapshots (use Artifactory).

How to deploy an arbitrary binary to Nexus with maven

I think I have run in to a maven deploy plugin bug, but I want to confirm that I am not doing it wrong before I open a bug report and start grepping through source.
I am trying to deploy an arbitrary binary (tar.gz,jar,box,etc) to a maven repository.
The user I am using is in the settings.xml file with a plaintext password.
The user is in an LDAP group that is connected to nexus with a Role.
That role has 3 privileges associated with it. Update, Create, Read which are in turn associated with the repository target.
Now using wget the user can pull data from the repo, and using this curl command I can deploy to the repo:
curl --request PUT --user USERNAME:PASSWORD https://NEXUS_URL/nexus/content/repositories/REPO_NAME/path/to/file/with/groupid/version/iamafile.jar \
--data #./iamafile.jar -H Content-Type:application/java-archive --verbose
This works fine, http 201 and the file is added. When I use a similiar mvn deploy command:
mvn deploy:deploy-file --settings /path/to/settings.xml \
-Durl=https://NEXUS_URL/nexus/content/repositories/REPOSITORYID -Dfile=iamafile.jar \
-DrepositoryId=REPOSITORYID -DartifactId=ARTIFACTID -DgroupId=GROUPID \
-Dversion=VERSION
I get an http 401 unauthorized error.
There have been multiple bug reports about this, but they supposedly have been fixed.
With a pom file with the same values for version, artifcatId, etc. mvn deploy works fine.
Have I found a bug, or am I using it improperly?
Edit:
I opened up this bug regarding the issue.
If the dev's end up saying that it isn't a bug, I will add that as an answer if someone hasn't beat me to it.
you need to additionally specify the -DrepositoryId

How to index a Maven repo without Nexus/Artifactory/etc?

I run my own little Maven repo for some open source. I have no dedicated server so I use a Google code repository, deploy to file system and then commit and push. Works perfect for me.
But some Maven tools are looking for a nexus-maven-repository-index.properties and the index (in GZ). I would like to generate this index to
get rid of the warning that it's not here
Maven doesn't try the repo for artefacts that are not there.
How can I do that? Is there a tool (Java main) that is able to generate an index? Also tips how to use the proper Nexus Jars with a little commandline tool are welcome.
I came across this post while I was searching for a solution to add a local repository to my Maven project using IntelliJ Idea.
Since Sonatype changed their paths and reorganized the downloads since the last post, here is an updated step-by-step tutorial to get your repository indexed for use with IntelliJ Idea:
Download the latest stand-alone indexer from here.
Extract it somewhere and go into this directory
From the console, run this command: export REPODIR=/path/to/your/local/repo/ && java org.sonatype.nexus.index.cli.NexusIndexerCli -r $REPODIR -i $REPODIR/.index -d $REPODIR/.index -n localrepo
In the directory .index within the repository directory, some files will be created including the file "nexus-maven-repository-index.gz" which is the file IntelliJ looks out for.
You can use the Maven Indexer CLI to product the index directly, but why bother hosting your own repo when OSS projects can use a hosted one for free?
http://nexus.sonatype.org/oss-repository-hosting.html
I was looking at maven indexer... but I am not sure what for is the last parameter indexDir in the method:
public RepositoryIndexer createRepositoryIndexer(String repositoryId,
File repositoryBasedir,
File indexDir)
is it like starting point in the repositoryBasedir?

Resources