在共享库Jenkins管道中使用CURL命令上载本地文件 [英] Upload Local File by Using CURL Command in Shared Library Jenkins Pipeline
本文介绍了在共享库Jenkins管道中使用CURL命令上载本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将文件从本地目录上传到远程目录.我有一个为此编写的Groovy库.
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!
如何确保文件设置正确? -F
方法是否正确?
How do I make sure that the file is set correctly? Also is the -F
approach correct?
推荐答案
该错误消息
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"(@
)符号
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}\""
这篇关于在共享库Jenkins管道中使用CURL命令上载本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文