MarcelHodan
MarcelHodan

Reputation: 630

upload artifact to artifactory with ant and curl results in empty file on server

I'm currently banging my head against this (wrong) behaviour. When I execute a CURL request in ant the upload results in a file with size=0 and when I execute the same request in the shell the file has the correct size.

ANT target output:

 [echo] path.toFile=/home/marcel/gitrepos/<repo>/source/<file>.zip
 [echo] path.targetFile=target/<file>.zip
 [echo] ------------
 [echo] curl -k -H 'X-JFrog-Art-Api: <API-KEY>
 [echo] ' -T "/home/marcel/gitrepos/<repo>/delivery/<file>.zip" "https://<company>.de/artifactory/stage-dev/target/<file>.zip"
 [echo] ------------
 [exec]   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
 [exec]                                  Dload  Upload   Total   Spent    Left  Speed
 [exec] 
 [exec] {
 [exec]   "repo" : "stage-dev",
 [exec]   "path" : "/target/<file>.zip",
 [exec]   "created" : "2018-02-27T16:12:25.397Z",
 [exec]   "createdBy" : "<user>",
 [exec]   "downloadUri" : "https://<company>.de:443/artifactory/stage-dev/target/<file>.zip",
 [exec]   "mimeType" : "application/zip",
 [exec]   "size" : "0",
 [exec]   "checksums" : {
 [exec]     "sha1" : "da39a3ee5e6b4b0d3255bfef95601890afd80709",
 [exec]     "md5" : "d41d8cd98f00b204e9800998ecf8427e"
 [exec]   },
 [exec]   "originalChecksums" : {
 [exec]   },
 [exec]   "uri" : "https://<company>.de:443/artifactory/stage-dev/target/<file>.zip"
 [exec] }
 [exec]   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0 5397k    0   752    0     0   2961      0 --:--:-- --:--:-- --:--:--  2972

ANT snippet: To execute the CURL command with ant I used this snippet:

<property name="artifactory.url" value="https://<company>.de/artifactory/stage-dev/"/>
    <target name="upload-latest-zip" depends="-read-api-key" description="=> upload latest zip to artifactory. requires (apikey-file).">
        <property name="path.toFile" location="source/${<file>}"/>
        <property name="path.targetFile" value="target/${<file>}"/>
        <echo message="------------" />
        <echo message="curl -k -H 'X-JFrog-Art-Api: ${apikey}' -T ${path.toFile} &quot;${artifactory.url}/${path.targetFile}&quot;" />
        <echo message="------------" />
        <exec executable="curl">
            <arg line="-k"/>
          <arg line="-H"/>
          <arg line="'X-JFrog-Art-Api: ${apikey}'"/>
          <arg line="-T"/>
          <arg line="${path.toFile}"/>
          <arg line="&quot;${artifactory.url}/${path.targetFile}&quot;"/>
        </exec>
    </target>

SHELL output To test the CURL it self I used the echoed command from the ant output.

marcel@Ubuntu:~/gitrepos/<repo>$ curl -k -H 'X-JFrog-Art-Api: <API-KEY>' -T "/home/marcel/gitrepos/<repo>/delivery/<file>.zip" "https://<company>.de/artifactory/stage-dev/target/<file>.zip"
{
  "repo" : "stage-dev",
  "path" : "/target/<file>.zip",
  "created" : "2018-02-27T16:12:25.397Z",
  "createdBy" : "<user>",
  "downloadUri" : "https://<company>.de:443/artifactory/stage-dev/target/<file>.zip",
  "mimeType" : "application/zip",
  "size" : "5526727",
  "checksums" : {
    "sha1" : "732c7ee866c06d2988abde8ec22ad1f9268f89fb",
    "md5" : "285c135f1551c2c07dec296c01d93160"
  },
  "originalChecksums" : {
  },
  "uri" : "https://<company>.de:443/artifactory/stage-dev/target/<file>.zip"

not shown in this question To verify this behaviour I also wrapped a shell script around the (upload) CURL command and called the shell script from ant instead of calling CURL directly. But it results in the same behaviour.

Currently we though about replacing the ant script with shell only. Anyhow I really want to know why this behaviour occurs!

Someone a good idea? :)

Additional information:

Used software:

  1. Ubuntu 16.04.3 LTS
  2. GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
  3. Apache Ant(TM) version 1.10.1 compiled on February 2 2017
  4. curl 7.47.0 (x86_64-pc-linux-gnu)
  5. java-8-openjdk-amd64
  6. Artifactory Enterprise 5.3.0

Upvotes: 1

Views: 2098

Answers (2)

Winni
Winni

Reputation: 1

A bit late, but in my case the API-KEY had a line break in the end. After using <striplinebreaks/>, it worked.

<target name="upload">
    <loadfile property="apikey" srcFile="${user.home}/.artifactory-secrets">
        <filterchain>
            <striplinebreaks/>
            <replaceregex pattern=".*:(.*)" replace="\1"/>
        </filterchain>
    </loadfile>
    <echo message="${basedir}" />
    <exec executable="curl" dir="${basedir}">
        <arg value="-svL" />
        <arg line="-H 'X-JFrog-Art-Api:${apikey}'" />
        <arg value="-H" />
        <arg value="content-type:application/octet-stream" />
        <arg value="-T" />
        <arg file="${basedir}/${dist}/myfile-${appversion}.jar" />
        <arg value="https://artifactory.appdomain.cloud/artifactory/generic-local/" />
    </exec>
</target>

Upvotes: 0

saurabh14292
saurabh14292

Reputation: 1401

What is the value of variable ${path.toFile} ?

[echo] path.toFile=/home/marcel/gitrepos/<repo>/source/<file>.zip

[echo] ' -T "/home/marcel/gitrepos/<repo>/delivery/<file>.zip" "https://<company>.de/...

/source or /delivery ? Is there anyway are you setting the value of same variable twice in ant? Since properties are immutable in ant, setting it twice/updating it won't work.

Upvotes: 1

Related Questions