Upload Local File by Using CURL Command in Shared Library Jenkins Pipeline

穿精又带淫゛_ 提交于 2019-12-06 13:17:09

问题


I am trying to upload a file from a local directory to a remote directory. I have a Groovy library that I have written to do this.

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()}']")
   }
  }

However, the above fails with the error:

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!

How do I make sure that the file is set correctly? Also is the -F approach correct?


回答1:


That error message

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

was seen in another context

The path needs an "at" (@) symbol before the .jtl file path

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

In your case, the double-quotes might be missing.

"\"files=@${file}\""


来源:https://stackoverflow.com/questions/56640699/upload-local-file-by-using-curl-command-in-shared-library-jenkins-pipeline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!