How do I deploy a file to Artifactory using the command line? - 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.

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"

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.

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.

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

$ 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

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.

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.

Related

Not able to download artifact from Nexus using curl

I am trying to download an artifact from Nexus Pro 3.37.3-02 using curl but it is not working. I have found below commands which I think working for many other but in my case I am getting repository, maven.groupId, maven.artifactId, maven.baseVersion, maven.extension is not recognized as internal or external command, operable program or batch files.
curl -u usename:password -L -X GET https://MY_NEXUS/service/rest/v1/search/assets/download?sort=version&repository=MY-REPO&maven.groupId=MY_GROUP&maven.artifactId=MY_ARTIFACT_NAME&maven.baseVersion=0.1-SNAPSHOT&maven.extension=zip
I have followed this documentation to make this command.
https://help.sonatype.com/repomanager3/integrations/rest-and-integration-api/search-api
Any help will be appreciated.
Thanks,
In case if anyone else facing the same problem then this is the solution which worked for me.
curl -u token:tokenPassword -L -X GET "https://MY_NEXUS/service/rest/v1/search/assets/download?sort=version&repository=MY-REPO&group=MY_GROUP&name=MY_ARTIFACT_NAME&version=MY_Version&maven.extension=zip" --output My_Artifact.zip

How to install Argo CLI?

I am trying to install Argo CLI by following this (https://github.com/argoproj/argo-workflows/releases) documentation.
# Download the binary
curl -sLO https://github.com/argoproj/argo/releases/download/v3.1.3/argo-linux-amd64.gz
# Unzip
gunzip argo-linux-amd64.gz
# Make binary executable
chmod +x argo-linux-amd64
# Move binary to path
mv ./argo-linux-amd64 /usr/local/bin/argo
# Test installation
argo version
The above instructions are not working. So, I followed the answer to this (How to update Argo CLI?) question.
curl -sLO https://github.com/argoproj/argo/releases/download/v2.12.0-rc2/argo-linux-amd64
chmod +x argo-linux-amd64
./argo-linux-amd64
But I am getting the following error:
./argo-linux-amd64: line 1: Not: command not found
I also tried moving the argo-linux-amd64 binary to /usr/local/bin/argo but still getting the same error (as expected).
Is there any solution to this?
Thank you.
The download links on the Releases page are incorrect. Try this one:
curl -sLO https://github.com/argoproj/argo-workflows/releases/download/v3.1.3/argo-linux-amd64.gz
I've submitted an issue to get the links fixed.

auto update of Jira tickets once build is done + VSTS

I am looking for some pluggin or script that automatically changes the ticket status to 'ready for qa' once a build is done. My deployment pipeline is set up in VSTS. Can someone help please.
You can change the status of Jira issue by rest API, in this way:
First, execute http://localhost:8100/rest/api/latest/issue/MTF -2/transitions?expand=transitions.fields and know the id’s for transitions.
For Eg: transition id for “Stop Progress” is 31, for “Done” is 41.
Once that is known, use the following link by adding values pertaining to your environment:
curl -D- -u <USER>:<PASS> -X POST --data '{"transition":{"id":"<TRANSITION_ID>"}}' -H "Content-Type: application/json" <JIRA_URL>:<JIRA_PORT>/rest/api/latest/issue/<JIRA_ISSUE>/transitions?expand=transitions.fields
So at the end of the VSTS build definition add a command line or PowerShell task and run the above curl command.
Note: you need curl installed on the build machine.

What command should I use with curl in terminal if I want to download an image from a website and put it in a certain folder?

I have seen
curl -o project/folder/image.png -OL example.com/image.png
Would this command work?
Edit: I figured it out

How do I retrieve an artifact checksum from Nexus using their rest api via curl?

I am trying to verify the checksum of the artifacts I am downloading from Nexus. I can grab the artifact and download them and check their md5sum or sha1sum, but I need to check this against the actual sum from Nexus so I can verify they are correct.
This is the command I'm using to grab files from Nexus:
curl -v -L -o /mylocation/artifact.war -u 'myuser:mypass' --get 'http://ournexus.com/service/local/artifact/maven/content?g=com.ours.stuff&a=our-service-war&v=LATEST&r=snapshots&p=war'
Via http://nexus.xwiki.org/nexus/nexus-indexer-lucene-plugin/default/docs/path__lucene_search.html, it would appear that I can also search for the sha1 sum, but when I do &sha1 I get nothing extra or sha1=(sum), nothing is pulled up, even if I omit all the above options.
This works, but it goes to a specific war, and we need the latest (obviously):
http://ournexus.com/service/local/repositories/snapshots/content/com/ours/stuff/ourapp/1.0.0-SNAPSHOT/ourapp-1.0.0-20140730.173704-88.war.sha1
Is this possible, am I on the right track?
You can either fetch the file directly or use the Nexus API to retrieve it programmatically.
The following URL:
http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central
Returns the following result:
<artifact-resolution>
<data>
<presentLocally>true</presentLocally>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<extension>jar</extension>
<snapshot>false</snapshot>
<snapshotBuildNumber>0</snapshotBuildNumber>
<snapshotTimeStamp>0</snapshotTimeStamp>
<sha1>55856d711ab8b88f8c7b04fd85ff1643ffbfde7c</sha1>
<repositoryPath>/log4j/log4j/1.2.9/log4j-1.2.9.jar</repositoryPath>
</data>
</artifact-resolution>
The xmllint command can be used to parse out the sha1 checksum value as follows:
$ curl -s "http://localhost:8081/nexus/service/local/artifact/maven/resolve?g=log4j&a=log4j&v=1.2.9&r=central" | xmllint --xpath "///sha1/text()" -
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 2
Use the artifact content API to directly get the MD5/SHA1 checksum file by specifying the p (packaging) or e (extension) parameter as jar.md5 or jar.sha1 (or other relevant for your actual packaging).
Example:
$ curl -s 'http://mynexus/service/local/artifact/maven/content?g=com.example&a=example&v=1.2.3&r=my-repo&e=jar.sha1'
55856d711ab8b88f8c7b04fd85ff1643ffbfde7c
Nexus 3
Use the Search API to find and download the asset.
$ curl -sL 'https://mynexus/service/rest/v1/search/assets/download?repository=my-repo&sort=version&maven.groupId=com.example&maven.artifactId=example&maven.baseVersion=LATEST-SNAPSHOT&maven.extension=jar.sha1&maven.classifier='
7ff1ca9fb889c73d095b69a52d5c8609482b63ab
The query below works for me
curl -u USER:PASS -X GET 'https://nexus.example.com:8443/service/rest/v1/search?repository=REPO_NAME&name=FILE_NAME' | jq '.items[0].assets[0].checksum'
Always good to check the API doc.
ps: username and password might be not needed for GET