Git:如何让用户在post-receive hook中进行推送?

时间:2011-12-21 00:59:06

标签: git jenkins

我有一个post-receive hook设置告诉Hudson构建之后,如果构建成功没有错误,Hudson会将更改合并回主分支。然而,这会导致进程再次启动,最终会进入无限循环。

如何获取用户,以便在hudson合并后我可以阻止Git进行构建?

我尝试过以下操作,但未设置$ user:

$user = ENV['USER']

1 个答案:

答案 0 :(得分:1)

好吧,如果您使用ssh进行连接,则可以使用$ USER,因为这似乎有效。如果这对你的ssh不起作用,只需运行“ssh someuser @ your-git-address env”来获取环境变量列表,因为所有这些都可以工作。

我的脚本用于阻止用户将更改推送到主人(但现在我需要弄清楚他们如何修复它以便他们可以通过干净拉动推送并从主人那里获得他们的更改,但将他们的更改移动到另一个分支或东西)...

#!/bin/sh
# <oldrev> <newrev> <refname>
# update a blame tree
while read oldrev newrev ref
do
    echo "STARTING [$oldrev $newrev $ref]"

if [ $ref == "refs/heads/master" ] && [ $USER != "hudson" ]
then
    echo "YOU CANNOT COMMIT STUFF TO MASTER BRANCH"
    echo "TO CORRECT THIS run"
    echo "git reset --soft HEAD^"
    echo "git branch -c <branch name> then run"
    echo "git push <reponame> <branch name>"
    echo "and hudson will take and push to master IF it passes the tests"
    exit 1;
else
    echo "This is hudson, allowing commit to master"
fi

done

这里的类似答案,但有两个脚本..

How can I stop myself from committing to the master branch in git?