Andrew Prock
Andrew Prock

Reputation: 7107

How do I deploy a file to Artifactory using the command line?

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.

Upvotes: 39

Views: 123857

Answers (9)

stackprotector
stackprotector

Reputation: 13412

With PowerShell (a PUT request with basic Auth):

Invoke-RestMethod -Uri 'https://my-artifactory.domain.tld/artifactory/my-repo/my-path/my-file.zip' -Method Put -InFile .\my-file.zip -Credential (New-Object System.Management.Automation.PSCredential -ArgumentList 'my-username', (ConvertTo-SecureString 'my-password-or-token' -AsPlainText -Force)) -ContentType 'multipart/form-data'

This may not work for files equal to or larger than 2 GiB. In this case, use the builtin curl.exe tool. Make sure to write curl.exe instead of just curl, as curl is an alias for the Invoke-WebRequest cmdlet in PowerShell:

curl.exe -u my-username:my-password-or-token -T my-file.zip 'https://my-artifactory.domain.tld/artifactory/my-repo/my-path/my-file.zip'

Upvotes: 0

Krishna
Krishna

Reputation: 473

This might be helpful for someone.

When we see in Artifactory UI, Application -> Artifactory -> Artifacts, By clicking required repository to deploy, Set me up -> Deploy provides URL option for deploy as

curl -uadmin: -T <PATH_TO_FILE> "https://<ARTIFACTORY_SERVER>/ui/<REPO_NAME>/<TARGET_FILE_PATH>" which gives 405 because URL is incorrect (ui in URL is incorrect).

The correct URL is curl -uadmin: -T <PATH_TO_FILE> "https://<ARTIFACTORY_SERVER>/artifactory/<REPO_NAME>/<TARGET_FILE_PATH>". This allows to deploy file.

PS: user's password is optional in curl command. If not provided in command, it will be prompted.

Additionally curl command is generally available in servers, so no need to set up Jfrog CLI for remote deploy.

Upvotes: 1

Saikat
Saikat

Reputation: 16710

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 must have write access to this path.

Upvotes: 10

Gilad Sharaby
Gilad Sharaby

Reputation: 998

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.

Upvotes: 19

Andrew Prock
Andrew Prock

Reputation: 7107

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.

Upvotes: 2

kazerm
kazerm

Reputation: 529

$ 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

Upvotes: 5

diptia
diptia

Reputation: 2245

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"

Upvotes: 60

Larry Cai
Larry Cai

Reputation: 59933

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

Upvotes: 5

JBaruch
JBaruch

Reputation: 22893

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.

Upvotes: 10

Related Questions