从Intellij Idea中从Gradle任务运行时,Bash脚本无法访问路径
我有一个 gradle 任务,它运行一个 bash 脚本,该脚本反过来清理一些 docker 容器,它是任务管道的一部分。
如果我从命令行运行此任务,它工作正常;如果我从 IntelliJ IDEA 中运行它,它会失败,因为我找不到 docker 命令。
这是任务:
task localDockerClean(type: Exec) {
executable './cleanDocker.sh'
ignoreExitValue true
}
这是脚本:
#! /bin/bash
echo "Init - Clean Docker Containers"
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker system prune --force --volumes
echo "End - Clean Docker Containers"
这是仅在从 IntelliJ IDEA 运行时才会发生的输出:
> Task :scripts:migrations:localDockerClean
Init - Clean Docker Containers
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 6: docker: command not found
End - Clean Docker Containers
看起来该脚本无法访问位于我的 MacOS 的 PATH 中的 docker 命令,但仅在从 IDE 运行时才会 发生,否则工作正常。
知道如何在我的 IDE 中解决这个问题吗?
谢谢你!
I have a gradle task which runs a bash script which in turn cleans up some docker containers, it's part of a pipeline of tasks.
If I run this task from the command line, it works fine; if I run it from within IntelliJ IDEA, it fails because I cannot find the docker
command.
This is the task:
task localDockerClean(type: Exec) {
executable './cleanDocker.sh'
ignoreExitValue true
}
This is the script:
#! /bin/bash
echo "Init - Clean Docker Containers"
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker system prune --force --volumes
echo "End - Clean Docker Containers"
And this is the output that only happens when run from IntelliJ IDEA:
> Task :scripts:migrations:localDockerClean
Init - Clean Docker Containers
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 4: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 5: docker: command not found
./cleanDocker.sh: line 6: docker: command not found
End - Clean Docker Containers
Looks like the script has no access to the docker command which is in the PATH in my MacOS but only when run from the IDE, otherwise it works fine.
Any idea how to fix this issue in my IDE?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论