一尘不染

在共享库Jenkins管道中使用CURL命令上载本地文件

jenkins

我正在尝试将文件从本地目录上传到远程目录。我有一个为此编写的Groovy库。

def file = "$WORKPLACE/**/*-${BUILD_NUMBER}-*/file.txt"

pulic uploadArtifct (String user, String password, String file, String 
  location) {
  def cred = "${user}:${password}"
  def cmd = ["curl", "-v", "-u", cred, "-F", "files=@${file}", ${location}]
  try {
   def sout = new StringBuffer(), serr = new StringBuffer()
   def proc = cmd.execute()
   proc.consumeProcessOutput(sout, serr)
   proc.waitForOrKill(1000)
   println sout
  } catch (Exception e) {
    throw new RuntimeExceptipon("Cannot execute curl, exception: [${e.getClass().getName()} - '${e.getMessage()}']")
   }
  }

但是,以上操作失败并显示以下错误:

java.lang.RuntimeException: Cannot execute curl, exception: [java.lang.RuntimeException - 'Error running ; stdout='', stderr='warning:setting file 
Warning: /app/jenkins/workspace/Job/**/*-10-*/file.txt 
Warning: failed!

如何确保文件设置正确?也就是-F方法正确吗?


阅读 371

收藏
2020-07-25

共1个答案

一尘不染

该错误信息

Cannot execute curl, exception: [java.lang.RuntimeException - 'Error running ; stdout='', stderr='warning:setting file 
Warning: /app/jenkins/workspace/Job/**/*-10-*/file.txt 
Warning: failed!

该路径@在.jtl文件路径之前需要一个“ at”()符号

-F "jtl_file=@/path/to/file"

在您的情况下,双引号可能会丢失。

"\"files=@${file}\""
2020-07-25