spuder
spuder

Reputation: 18407

Artifactory upload with checksum

If you upload an artifact to Artifactory and don't provide a checksum, it gives this warning:

Screenshot, Artifactory, Fix Checksum

How do you upload with curl and include a checksum?

Upvotes: 31

Views: 24006

Answers (3)

Jim
Jim

Reputation: 179

This is working for me in 7.4.3 for MD5, SHA1 and SHA256.

for file in $(find a_folder -type f)
do
    ARTIFACT_MD5_CHECKSUM=$(md5sum $file | awk '{print $1}')
    ARTIFACT_SHA1_CHECKSUM=$(shasum -a 1 $file | awk '{ print $1 }')
    ARTIFACT_SHA256_CHECKSUM=$(shasum -a 256 $file | awk '{ print $1 }')

    echo curl --upload-file $file \
            --header "X-Checksum-MD5:${ARTIFACT_MD5_CHECKSUM}" \
            --header "X-Checksum-Sha1:${ARTIFACT_SHA1_CHECKSUM}" \
            --header "X-Checksum-Sha256:${ARTIFACT_SHA256_CHECKSUM}" \
            -u "admin:${APIKEY}" \
            -v http://URL/$file
done

Upvotes: 18

gangefors
gangefors

Reputation: 40

Since I'm not allowed to comment I will post a clarification as an answer.

This comment suggests that the Deploy Artifact by Checksum API is the documentation regarding uploads with checksum verification. But that is only valid for uploads of artifacts that already exist in Artifactory. As documented, it will reject new artifact uploads with a 404.

Upvotes: 1

spuder
spuder

Reputation: 18407

This feature currently isn't well documented, an example is found on this page:

https://www.jfrog.com/knowledge-base/what-are-client-checksum-server-checksum-and-checksum-policy-in-local-repositories/

Simply add the following to the curl command: "--header "X-Checksum-<type>:${CHECKSUM}"

Sha1

CHECKSUM=$(shasum -a 1 foo.zip | awk '{ print $1 }')

curl --header "X-Checksum-Sha1:${CHECKSUM}" --upload-file "foo.zip -u "admin:<apikey>" -v https://artifactory.example.com/foo/

MD5

CHECKSUM=$(md5sum foo.zip | awk '{ print $1 }')

curl --header "X-Checksum-MD5:${CHECKSUM}" --upload-file "foo.zip -u "admin:<apikey>" -v https://artifactory.example.com/foo/

Or provide both checksums at once

ARTIFACT_MD5_CHECKSUM=$(md5sum foo.zip | awk '{print $1}')
ARTIFACT_SHA1_CHECKSUM=$(shasum -a 1 foo.zip | awk '{ print $1 }')
curl --upload-file "foo.zip" \
--header "X-Checksum-MD5:${ARTIFACT_MD5_CHECKSUM}" \
--header "X-Checksum-Sha1:${ARTIFACT_SHA1_CHECKSUM}" \
-u "admin:<apikey>" \
-v https://artifactory.example.com/foo/

Unfortunatley, uploading with the sha256 doesn't work with curl because of a bug

Upvotes: 47

Related Questions