2

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?

SSF
  • 915
  • 5
  • 23
  • 47

1 Answers1

2

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}\""
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    @SSF You are welcome. I have reported the "double-quotes" requirement in my answer of your previous question. – VonC Jun 18 '19 at 06:27