我正在尝试将文件从本地目录上传到远程目录。我有一个为此编写的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
方法是否正确?
答案 0 :(得分: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!
在another context中看到了
该路径在.jtl文件路径之前需要一个“ at”(@
)符号
-F "jtl_file=@/path/to/file"
在您的情况下,双引号可能会丢失。
"\"files=@${file}\""