automation - 位桶网络钩子(Hook)

标签 automation bitbucket git scripting

我想将我的一个项目自动部署到我的服务器上。 我通过 bitbucket 使用 git 来对我的软件进行版本控制。 我遇到了这个 this不错的教程。不幸的是我无法让它工作。

如果我从我的本地工作副本推送更改,远程仓库会更新,但 webhook 会给我 404错误。因此与我的服务器建立了通信,但未找到脚本。

当我通过 php bitbucket-hook.php 手动启动脚本时在 repo 协议(protocol)上发出 pull 请求,一切都按预期进行。

我猜 URL 有问题。我试过 http://ip.ip.ip.ip/home/<username>/app/deploy/bitbucket-hook.php还有域名。

最佳答案

我自己实现了 webhook 很多次。

您用来访问 .php 文件的路径不正确。这个路径应该是相对于你的apache DocumentRoot (eg/var/www/html)

假设您的 DocumentRoot 是/var/www/html 然后将您的 bitbucket-hook.php 文件放入此路径(即/var/www/html/bitbucket-hook.php)并使用 URL 作为 http://ip.ip.ip.ip/bitbucket-hook.php

或者,您可以创建一个指向/(root)的虚拟主机并使用 http://ip.ip.ip.ip/home/ {用户名}/app/deploy/bitbucket-hook.php

注意:您还需要在/var/www 中添加带有私钥的 .ssh 文件夹,因为当您触发 webhook 时,apache 将在其主文件夹中找到 key ,即/var/www。

这是我为自动部署编写的 bash 的一部分

`

echo "implenting the web hook for auto deployment..."
if ! [[ -d /var/www/.ssh ]]; then
sudo cp -R ~/.ssh /var/www/
if [[ \$? == 0 ]];then
echo -e 'copied ~/.ssh to document root to apache [/var/www]\n'
else
echo -e 'something went wrong while copying ~/.ssh to /var/www\n'
fi
else
echo "Already a folder name .ssh in /var/www"
fi
sudo chown -R apache. /var/www/.ssh 2>&1
if [[ \$? == 0 ]];then
echo -e 'ownership of /var/www/.ssh has changed to apache \n'
else
echo -e 'something went wrong while changing ownership of /var/www/.ssh\n'
fi
pushd /var/www/html
touch auto_pull.php
sudo chown apache. auto_pull.php
echo -e "<?php content to write in php file ?>">>auto_pull.php  
popd

`

我希望这会有所帮助:)

关于automation - 位桶网络钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31128021/

相关文章:

automation - 7zip 的 7z.sfx 和 7zsd.sfx 有什么区别?

git - 恢复到 bitbucket 中之前的更改

git - 获取 Bitbucket 私有(private)存储库时出错

Git:显示在两个修订版之间更改的所有文件的提交内容

git checkout : detailed meaning of "theirs" and "ours"

java - 方法访问日志记录的自动化或快捷方式

ios - iOS自动化-从相机胶卷中选择照片

automation - 使用 Arduino 进行照明控制

Git SourceTree - 未提交的子模块

git - 远程分支没有出现在 "git branch -r"