【问题标题】:upload artifact to artifactory with ant and curl results in empty file on server使用 ant 将工件上传到工件并 curl 导致服务器上的文件为空
【发布时间】:2018-02-28 07:04:30
【问题描述】:

我目前正在反对这种(错误的)行为。 当我在 ant 中执行 CURL 请求时,上传会生成一个具有 size=0 的文件,而当我在 shell 中执行相同的请求时,该文件具有 正确的大小。

ANT 目标输出:

 [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 sn-p: 为了用 ant 执行 CURL 命令,我使用了这个 sn-p:

<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 输出 为了自己测试 CURL,我使用了 ant 输出中的 echoed 命令。

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 为了验证这种行为,我还在(上传)CURL 命令周围包裹了一个 shell 脚本,并从 ant 调用 shell 脚本,而不是直接调用 CURL。但它会导致相同的行为。

目前我们只考虑用 shell 替换 ant 脚本。无论如何,我真的很想知道为什么会发生这种行为!

有人是个好主意吗? :)

其他信息:

使用过的软件:

  1. Ubuntu 16.04.3 LTS
  2. GNU bash,版本 4.3.48(1)-release (x86_64-pc-linux-gnu)
  3. Apache Ant(TM) 版本 1.10.1 编译于 2017 年 2 月 2 日
  4. curl 7.47.0 (x86_64-pc-linux-gnu)
  5. java-8-openjdk-amd64
  6. Artifactory Enterprise 5.3.0

【问题讨论】:

    标签: bash curl ant artifactory put


    【解决方案1】:

    变量 ${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 还是 /delivery ? 无论如何,您是否在 ant 中两次设置相同变量的值?由于属性在 ant 中是不可变的,因此设置它两次/更新它是行不通的。

    【讨论】:

    • 变量 包含我要上传的文件的绝对路径。也许我删除了机密信息是一个错误。但是 设置正确。
    【解决方案2】:

    有点晚了,但在我的情况下,API-KEY 最后有一个换行符。 使用 后,它工作了。

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-06
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 2013-06-09
      • 2013-06-24
      • 2015-12-15
      • 2011-06-18
      相关资源
      最近更新 更多