如果脚本存在且代码为 0,则提交挂钩不会打印任何错误消息

发布于 2024-11-07 20:30:35 字数 980 浏览 0 评论 0原文

我的预提交正在调用一个perl脚本commit_log.pl。该脚本正在执行如此多的预检查。现在我尝试在提交批准后发送邮件。我们无法设置由于一些权限问题,后提交挂钩。所以我尝试在预提交脚本本身中调用发送邮件。

在我的 commit_log.pl 中,如果退出代码为零,即使 printf 也不起作用。

如果退出代码为 1,则一切正常

预提交

log=`$SVNLOOK log -t "$TXN" "$REPOS"`
author=`$SVNLOOK author -t "$TXN" "$REPOS"`
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS"`

/usr/bin/perl /isource/svnroot/fgw_ins/hooks/user/commit_log.pl "$log" "$author" "$CHANGED" "$0" 1>&2

if [ "$?" -eq "1" ];
then
        exit 1
else
        exit 0
fi

# if does not match..fail...
exit 1
---------------------------------------------------------------------------------
commit_log.pl
------------------------


}
   else
                {
                        print("Commit approved\n");#this printf itself is not working
                        `python $path/send_mail.py $comment $committed_filepath`;
                        exit 0;
                }

My pre-commit is calling a perl script commit_log.pl.The script is doing so many pre-checks.Now I am trying to send out a mail after commit approval.We are not able to set up post-commit hooks due to some permission issues.So I am trying to call the send mail in the pre-commit script itself.

In my commit_log.pl if the exit code is zero ,even printf is not working.

If exit code is 1 everything is working fine

pre-commit:

log=`$SVNLOOK log -t "$TXN" "$REPOS"`
author=`$SVNLOOK author -t "$TXN" "$REPOS"`
CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS"`

/usr/bin/perl /isource/svnroot/fgw_ins/hooks/user/commit_log.pl "$log" "$author" "$CHANGED" "$0" 1>&2

if [ "$?" -eq "1" ];
then
        exit 1
else
        exit 0
fi

# if does not match..fail...
exit 1
---------------------------------------------------------------------------------
commit_log.pl
------------------------


}
   else
                {
                        print("Commit approved\n");#this printf itself is not working
                        `python $path/send_mail.py $comment $committed_filepath`;
                        exit 0;
                }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鱼忆七猫命九 2024-11-14 20:30:35

无法为 Avi 的答案添加更多内容:STDOUT 被钩子吞噬。您将永远看到 STDOUT。仅当挂钩脚本返回非零退出代码时,客户端才会看到 STDERR——这通常意味着挂钩失败,并且在预提交挂钩中会阻止提交。

如果您需要在提交后发送邮件,并且无法使用提交后挂钩,我建议您使用连续构建系统,例如 詹金斯。您可以让 Jenkins 监视您的存储库,当它看到新修订时,向相关人员发送电子邮件。

Jenkins 是一个持续构建系统,可以在每次提交后进行构建,但没有理由需要进行构建(除非它通常是一个好主意)。 Jenkins 可以设置为在提交后执行任何操作,因此您可以让 Jenkins 只需向相关人员发送电子邮件即可。

是的,拥有像 Jenkins 这样的整个系统只是为了发送电子邮件有点过分了。为什么不直接编写自己的脚本呢?但是,您可以在一两个小时内下载、安装和配置 Jenkins。仅仅布置你认为需要完成的事情就需要花费更长的时间。

此外,一旦您拥有了 Jenkins,您就会发现它还有很多其他用途。

Can't add much more to Avi's answer: STDOUT is swallowed by the hook. You will NEVER see STDOUT. STDERR is only seen by the client if the hook script returns a non-zero exitcode -- which usually means the hook failed, and in a pre-commit hook prevents the commit.

If you need to send mail out after a commit, and you can't use a post-commit hook, I suggest you use a continuous build system like Jenkins. You can have Jenkins watch your repository, and when it sees a new revision, send out email to those involved.

Jenkins is a continuous build system which can do a build after every commit, but there's no reason why you need to do a build (except it is usually a good idea anyway). Jenkins can be setup to do any action post commit, so you could have Jenkins simply email those involved.

Yes, it's a bit of an overkill having an entire system like Jenkins just to send out email. Why not simply write your own script? However, you can download, install, and configure Jenkins in an hour or two. It'll take you longer just to layout what you think needs to be done.

Besides, once you have Jenkins, you'll find plenty of other uses for it.

忆悲凉 2024-11-14 20:30:35

我不确定预提交挂钩的标准输出发送到哪里。根据 SVN 书籍,标准错误被发送回客户端,但前提是存在错误(即以非零退出代码退出)。

我会尝试写入特定位置,而不是标准输出(例如用于测试目的的 /tmp/pre-commit.log )。

另外,一般来说,您可能应该尽可能避免在假设提交成功的预提交脚本中进行工作。在预提交脚本运行后,提交可能仍然会失败,例如在提交本身期间,这就是存在后提交脚本的原因。

I'm not sure where standard output from the pre-commit hook is sent to. According to the SVN book, the standard error is sent back to the client, but only if there is an error (i.e. it exited with a non-zero exit code).

I would try writing to a specific location, rather than to standard output (e.g. /tmp/pre-commit.log for testing purposes).

Also, in general, you probably should avoid as much as possible doing work in the pre-commit script that assumes the commit was successful. The commit may still fail after the pre-commit script runs, such as during the commit itself, which is why the post-commit script exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文