36

I've spent far more time on this than I care to admit. I am trying to just deploy one file into my Artifactory server from the command line. I'm doing this using gradle because that is how we manage our java builds. However, this artifact is an NDK/JNI build artifact, and does not use gradle.

So I just need the simplest gradle script to do the deploy. Something equivalent to:

scp <file> <remote>

I am currently trying to use the artifactory plugin, and am having little luck in locating a reference for the plugin.

Andrew Prock
  • 6,900
  • 6
  • 40
  • 60

7 Answers7

54

curl POST did not work for me . PUT worked correctly . The usage is

curl -X PUT $SERVER/$PATH/$FILE --data-binary @localfile

example :

$ curl -v --user username:password --data-binary @local-file -X PUT "http://<artifactory server >/artifactory/abc-snapshot-local/remotepath/remotefile"
Hamid Nazari
  • 3,905
  • 2
  • 28
  • 31
diptia
  • 2,135
  • 21
  • 21
  • I get a '401: Unauthorized' no matter what I do. I've tried several users credentials which work through teamcity but no dice. – sirdank Dec 10 '15 at 21:18
  • Your 401 might be due to the type of authorization your server uses. You may need to set the auth in the header of your PUT. Something like -H "Authorization: Basic YXBpdXNlcjphcGlwd2Q=" – Jason Slobotski Sep 23 '16 at 20:50
  • 4
    Note that artifactory will not handle the checksums automatically. To have them generated, the "Checksum" header must be included. i.e. `curl -H"X-Checksum-Md5:8a0daa40b5b6683897fa319b6a67c090" -H"X-Checksum-Sha1:586d62d7f56b58dc12d32800ba025b424cfd7429" ...`. – Elist Jul 12 '17 at 20:51
16

Instead of using the curl command, I recommend using the jfrog CLI.

Download from here - https://www.jfrog.com/getcli/ and use the following command (make sure the file is executable) -

./jfrog rt u <file-name> <upload-path>

Here is a simple example:

./jfrog rt u sample-service-1.0.0.jar libs-release-local/com/sample-service/1.0.0/

You will be prompted for credentials and the repo URL the first time.

You can do lots of other stuff with this CLI tool. Check out the detailed instructions here - https://www.jfrog.com/confluence/display/RTF/JFrog+CLI.

Peter Sobot
  • 2,476
  • 21
  • 20
Gilad Sharaby
  • 910
  • 9
  • 12
9

The documentation for the artifactory plugin can be found, as expected, in Artifactory User Guide.

Please note that it is adviced to use the newer plugin - artifactory-publish, which supports the new Gradle publishing model.

Regarding uploading from the command line, you really don't need gradle for that. You can execute a simple PUT query using CURL or any other tool.

And of course if you just want to get your file into Artifactory, you can always deploy it via the UI.

JBaruch
  • 22,610
  • 5
  • 62
  • 90
  • Unfortunately the documentation is lacking. For example, there is no reference for the DSL used, and the example script has syntax errors in it. Deploying by the UI is not an option, as this is for CI. I'm currently working on the REST API. – Andrew Prock Nov 19 '13 at 00:44
  • It's also not clear how to populate the maven pom metadata from the REST API. – Andrew Prock Nov 19 '13 at 00:54
  • I am not sure why the downvote. I answered your questions precisely, both how to deploy from cmd (by REST) and where's the reference to plugin (in the user guide). Looks like you wanted to ask something else, that's fine, but I am not sure how the answers are bad. – JBaruch Nov 19 '13 at 13:03
  • The guide documents every possible value in the DSL. What do you miss? – JBaruch Nov 19 '13 at 13:06
  • The generation of a POM file is not documented in the docs because it's not available trough REST. You'll have to write a simple gradle build with maven-publish to achieve that. I'll be glad to guide you throw that, but I think it worth its own question. – JBaruch Nov 19 '13 at 13:06
  • 1
    Pointing to sparse documentation is not answering a question. Do you have an example script (gradle, etc) which will upload and generate a pom? – Andrew Prock Nov 19 '13 at 17:27
  • As for documentation, compare the REST documentation: http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API to the artifactory-publish documentation: http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin. One is clearly well documented, and the other is not. – Andrew Prock Nov 19 '13 at 17:33
  • Downvoted because this answer does not actually provide any useful information. – Steven Byks May 05 '17 at 18:59
5

Take a look the Artifactory REST API, mostly you can't use scp command, instead use the curl command towards REST API.

$ curl -X POST $SERVER/$PATH/$FILE --data @localfile

Mostly it looks like

$ curl -X POST http://localhost:8081/artifactory/abc-snapshot-local/remotepath/remotefile --data @localfile

The scp command is only used if you really want to access the internal folder which is managed by artifactory

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
Larry Cai
  • 55,923
  • 34
  • 110
  • 156
3
$ curl -v -X PUT                    \
  --user username:password          \
  --upload-file <path to your file> \
  http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar
slm
  • 15,396
  • 12
  • 109
  • 124
kazerm
  • 499
  • 1
  • 4
  • 11
  • Is it possible to download a file from oneartifactory from batch command .? – Bala Mar 06 '17 at 12:09
  • you can use wget: something like that: wget --user="" --password="" --no-check-certificate -P .-r --no-parent --reject "index.html*" --no-parent --recursive --relative --level=1 --no-directories http://localhost:8080/artifactory/libs-release-local/my/jar/1.0/jar-1.0.jar – kazerm Mar 14 '17 at 20:20
2

Ironically, I'm answering my own question. After a couple more hours working on the problem, I found a sample project on github: https://github.com/JFrogDev/project-examples

The project even includes a straightforward bash script for doing the exact deploy/copy from the command line that I was looking for, as well as a couple of less straightforward gradle scripts.

Andrew Prock
  • 6,900
  • 6
  • 40
  • 60
2

As per official docs, You can upload any file using the following command:

curl -u username:password -T <PATH_TO_FILE> "https://<ARTIFACTORY_SERVER>/<REPOSITORY_PATH>/<TARGET_FILE>"

Note: The user should have write access to this path.

Saikat
  • 14,222
  • 20
  • 104
  • 125