Docker Webhook 容器:应该 运行 脚本,但脚本没有正确执行(只有 echo 有效)

Docker Webhook container: Should run a script, but the script doesn't get executed correctly (only echo's are working)

所以我设置了一个 Docker 容器,它基于 almir/webhook 中的容器,我在图像中添加了 git 和 docker,所以我可以运行 相应的命令。问题是,当我手动测试它时它 运行s 甚至当我通过终端从容器内部启动脚本时它甚至 运行s 。但是当我通过 URL 触发脚本时,我只得到回声作为输出,没有执行 "real" 命令。

我的脚本如下所示:

#!/bin/sh

echo "current directory: " + $PWD
git pull
echo "pulling from git"
docker exec -ti geda-drupal gedankenbruecke/vendor/drush/drush/drush st
echo "clear drupal cache"
echo "Script finished successful"
echo "testPull"

我的输出是这样的:

[webhook] 2017/10/03 21:08:58 incoming HTTP request from 172.18.0.4:38050
[webhook] 2017/10/03 21:08:58 tuleapPull got matched
[webhook] 2017/10/03 21:08:58 tuleapPull hook triggered successfully
[webhook] 2017/10/03 21:08:58 2017-10-03T21:08:58Z | 200 |   61.3µs | webhook.localhost | GET /hooks/tuleapPull 
[webhook] 2017/10/03 21:08:58 executing /var/webhook/scripts/tuleapPull.sh (/var/webhook/scripts/tuleapPull.sh) with arguments ["/var/webhook/scripts/tuleapPull.sh"] and environment [] using /var/repo/ as cwd
[webhook] 2017/10/03 21:08:58 command output: current directory:  + /var/repo
pulling from git
clear drupal cache
Script finished successful
testPull

[webhook] 2017/10/03 21:08:58 finished handling tuleapPull

所以脚本似乎正确执行了,但重要的命令却没有。我通过对我的存储库进行新的推送来测试它,这会触发 webhook-Url 然后它应该让容器从存储库中拉出,但这并没有发生。只有当我手动启动脚本时,脚本才能正确执行。

有没有人提供一些提示可能是哪里的问题?

Only when I start the script manually, the script gets executed correctly.

一个可能的原因是两种情况下使用的环境变量和用户帐户不同。
尝试在脚本中显示它们(使用 envid -a)以查看两种执行模式(手动或通过 webhook)之间的差异

从我的角度来看,您的问题似乎是缺少 TTY

docker exec -ti geda-drupal gedankenbruecke/vendor/drush/drush/drush st

您需要 TTY 才能使此命令正常工作,这不是必需的

docker exec -ti geda-drupal gedankenbruecke/vendor/drush/drush/drush st

下一期可能没有完整的命令路径。有时在此类执行中未定义 PATH 变量,这会导致问题。所以你最好用完整的路径替换路径

#!/bin/sh

echo "current directory: " + $PWD
/usr/bin/git pull
echo "pulling from git"
/usr/bin/docker exec -ti geda-drupal gedankenbruecke/vendor/drush/drush/drush st
echo "clear drupal cache"
echo "Script finished successful"
echo "testPull"