【发布时间】:2015-07-27 00:49:56
【问题描述】:
我想在 Uno-Choice 动态参考参数中调用一个 shell 脚本 并执行一些操作(创建一些文件并调用其他一些 shell 来自被调用的 shell 脚本的脚本)。
到目前为止,我可以调用 shell 脚本和 cat 一些文件,但我不能 在其中创建新文件或调用另一个 shell 脚本。
def sout = new StringBuffer(), serr = new StringBuffer()
// 1)
def proc ='cat /home/path/to/file'.execute()
//display contents of file
// 2)
def proc="sh /home/path/to/shell/script.sh".execute()
//to call a shell script but the above dosent work if I echo some contents
//into some file.
proc.consumeProcessOutput(sout, serr)
proc.waitForOrKill(1000)
return sout.tokenize()
例如:- 在script.sh 如果我添加行
echo "hello world" > test
则不创建测试文件
更多理解:
【问题讨论】:
-
什么不起作用?痕迹,错误,...?
-
尝试
sh echo "hello world" > test或更好的echo "hello world" > /tmp/test,以防万一它正常工作但您找不到文件。 -
谢谢波西米亚人。但它也不起作用。
-
确保在正确的位置搜索文件。尝试使用绝对路径并检查 Jenkins 主文件系统。在 Jenkins 中,groovy 通常在 master 上执行。