这里有一个摇篮的任务,停止Tomcat服务器的例子:
task stopTomcat(type:Exec) {
workingDir '../tomcat/bin'
//on windows:
commandLine 'cmd', '/c', 'stop.bat'
//on linux
commandLine './stop.sh'
//store the output instead of printing to the console:
standardOutput = new ByteArrayOutputStream()
//extension method stopTomcat.output() can be used to obtain the output:
ext.output = {
return standardOutput.toString()
}
}
这也是一个很好的例子,因为在这几个有用的指令。
在你的情况下,它会是这样的:
task testFile(type:Exec) {
workingDir '/home/user'
commandLine './test.sh'
}
更多信息,可以发现here。
谢谢你的评论。我知道如何执行命令,但是如何处理bash脚本(或其他程序)的退出代码以使“测试”(而不是构建)失败? – Dominik