How to download folder artifact from artifactory - shell

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.

Related

Yaml script to download the most recent Artifact from Artifact repository

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/

Copy the latest artifact in the artifactory CURL

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"

Maven : pom.lastUpdated exists but no jar [duplicate]

I have an Eclipse setup with m2eclipse and subversive. I have imported a maven2 project from svn. But I get the error message that a whole bunch of artifacts are missing (for instance: Missing artifact org.springframework:spring-test:jar:3.0.1.RELEASE:test).
If I look in my repository I see the jar files there but they have an extra extension .lastUpdated. Why is maven appending .lastUpdated to the jars? And more importantly: how can I fix this?
There is no mention of the type lastUpdated in my POMs.
These files indicate to Maven that it attempted to obtain the archive by download, but was unsuccessful. In order to save bandwidth it will not attempt this again until a certain time period encoded in the file has elapsed. The command line switch -U force maven to perform the update before the retry period. This may be necessary if you attempted to build while disconnected from the network.
The method of removing the files works with most versions of maven, but since the files are internal mementos to maven, I would not recommend this method. There is no guarantee that this information is not referenced or held elsewhere and such manipulation can damage the system.
As rperez said, I use to delete all those .lastUpdated files. In Linux I have created a little script to keep it simple:
find -name \*.lastUpdated -exec rm -fv {} +
Just create a file with the previous content and put it on your local Maven repository. Usually it will be ~/.m2/repository.
I installed Maven2 and ran mvn compile from the command line. This seems to have resolved the problem
you might have a problem with some of the artifacts to be retrieved from the repository. for example spring framework has its own repository. this xtension is appended when the artifact cannot fully downloaded. add the spring framework repository to your pom or settings.xml, delete the folder that include the broken jars and start again
If you hit this problem and you're using Nexus, it might be the case that you have a routing rule defined, which is incorrect. I hit this myself and the files it was downloading were correctly named, at the proper URL-s it was looking at, but they were all with the .lastUpdated extension and an error message as contents.
Open your terminal, navigate to your Eclipse's project directory and run:
mvn install
If mvn install doesn't update your dependencies, then call it with a switch to force update:
mvn install -U
This is a much safer approach compared to tampering with maven files as you delete ".lastUpdated".
Use this command inside the .m2/repository dir to rename all files:
for file in `find . -iname *.lastUpdated`; do renamed=$(echo $file | rev | cut -c13- | rev); echo renaming: $file to $renamed; mv $file $renamed; done
This is usefull to not download all sources again.
This not work... The .jar is lost. :(
What I do when I encounter this issue:
Make sure you have the version of the latest 'maven-source-plugin' plugin:
https://maven.apache.org/plugins/maven-source-plugin/usage.html
$ mvn source:jar install
Now if the file *.lastUpdate exist in your local ~/.m2/repositories/your-lib/0.0.1/ directory you can just remove it then run the command above again.
This is a side-effect of a failure to successfully extract from the repository. To get the actual content you want into your repository, check for correct paths to the repository/repositories within your pom file, and resolve certificate/security issues, if any. It is almost invariably one or the other of these issues.
There is no need to delete the .lastUpdated entries, and doing so won't solve your problem.

How to run mvn if there is no maven installed on the target machine

Is it possible to run mvn commands if there is no maven installed on the target machine? I know this is a strange one.
Is this possible using some wrapper tool/utility which has maven/etc tools inbuilt in the wrapper tool/utility?
This is what I'm trying to achieve. Using Ansible (and Maven) to get an artifact to a given folder from a remote Artifactory server.
I want to download an artifact from Artifactory.
The target machine doesn't have maven(mvn) installed.
If I create a small one liner shell script then I have to deal with all the repositories one by one i.e. in some order (i.e. look into release repo first, then way down to snapshot etc or vice versa).
(wget http://myArtifactoryServer:somePort/artifactory/libs-snapshot-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-stage-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-alpha-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-beta-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-gamma-local/com/company/product/artifactName/version/artifactNameVersion.extension || wget http://myArtifactoryServer:somePort/artifactory/libs-release-local/comcompany/product/artifactName/version/artifactNameVersion.extension )
I was wondering if there's any other easiest way I can grab an artifact by just giving "virtual repo name" i.e. libs-release (which I have created and looks into all physical release repos or just use company-repos virtual so that I don't have to name each repo name one by one using || or with wget).
I don't have to use wget either if there's any other way around. Maven automatically finds the artifact and search in all the repos (what you define in settings.xml or pom.xml or at command line maven-dependency-plugin:get/copy)
I can also write code in groovy but then groovy has to be there on the target server.
Late to the party, but nonetheless:
Having re-read the question, what you're missing is, as you mention, a virtual repo, which combines repos so they appear to be one. Artifactory supports this out of the box.
As an alternative to maven that requires nothing other than bash, you could try this shell script from sonatype http://blog.sonatype.com/2011/01/downloading-artifacts-from-nexus-with-bash.

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