我想使用build.gradle中的gradle运行此命令“ docker exec -it bash -c'./tmp/script.sh”。但是,尽管“ docker ps -a”命令可以正常工作,该命令也不起作用
我尝试了不同的方法,但是没有运气
1) "docker-compose exec resin_container bash -c './resin/bin/resin-shutdown.sh'".execute().waitFor()
2) CommandLine "docker-compose exec resin_container bash -c './resin/bin/resin-shutdown.sh'"
3) exec{
executable = 'sh'
args "docker-compose exec resin_container bash -c './resin/bin/resin-shutdown.sh'"
}
build.gradle上的完整代码如下所示
task dockerDeploy(dependsOn: 'tarArtifact') {
group = "dev"
description = 'Create exploded-war, tar it and deploy to docker'
doLast {
if (devEnvironment) {
if ("docker inspect -f '{{.State.Running}}' resin_container".execute().text.contains('true')) {
println "SHUTTING DOWN Resin Service"
"docker-compose ps".execute().waitFor()
//"docker-compose exec resin_container bash -c './resin/bin/resin-shutdown.sh'".execute().waitFor()
def resin_shutdown = "docker exec -it resin_container bash -c \"./resin/bin/resin-shutdown.sh\""
println "${resin_shutdown}"
exec{
//commandLine = 'docker ps'
commandLine = resin_shutdown
}
println "RESTARTING resin_container"
"docker-compose restart resin_container".execute().waitFor()
} else {
println "STARTING services"
"docker-compose up -d".execute()
}
}
}
}
预期的结果如下。在这里,我从shell终端运行命令,但是我想使用gradle build运行相同的命令
uzzal$ docker exec -it resin_container bash -c "./resin/bin/resin-
shutdown.sh"
+ GREEN='\033[1;32m'
+ NC='\033[0m'
+ echo 'NODE_NAME : '
NODE_NAME :
+ pushd .
+ echo 'Waiting for server to stop'
Waiting for server to stop
+ sleep 3
+ pgrep -fl -U 999 resin.jar
+ awk '{ print $1 }'
+ xargs kill -SIGTERM
+ sleep 3
+ echo -e '\033[1;32m DONE SHUTTING DOWN \033[0m '
DONE SHUTTING DOWN
+ popd
uzzal$
但是输出为
FAILURE: Build failed with an exception.
出了什么问题: 任务':app:shutResin'的执行失败。
启动过程'命令'docker exec -it resin_container bash -c“ ./resin/bin/resin-shutdown.sh”“
尝试: 使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行,以获取更多日志输出。