Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git:如何让用户在post接收钩子中进行推送?_Git_Jenkins - Fatal编程技术网

Git:如何让用户在post接收钩子中进行推送?

Git:如何让用户在post接收钩子中进行推送?,git,jenkins,Git,Jenkins,我有一个post-receive-hook设置来告诉Hudson进行构建,之后如果构建成功且没有错误,Hudson会将更改合并回主分支。然而,这会导致进程再次启动,我最终进入一个无限循环 当hudson合并回来时,我如何获得用户以便阻止Git进行构建 我尝试了以下选项,但未设置$user: $user = ENV['USER'] 好的,如果您使用ssh进行连接,那么可以使用$USER,因为这似乎是可行的。如果您的ssh不起作用,只需运行“ssh”someuser@your-git addres

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

当hudson合并回来时,我如何获得用户以便阻止Git进行构建

我尝试了以下选项,但未设置$user:

$user = ENV['USER']

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

我的脚本用于防止用户将更改推送到master(但现在我需要弄清楚他们如何修复它,以便他们可以直接从master中推送并获得更改,但将更改移动到另一个分支或其他地方)

#/垃圾箱/垃圾箱
#   
#更新责备树
当读取oldrev newrev ref时
做
echo“开始[$oldrev$newrev$ref]”
如果[$ref==“refs/heads/master”]&&&[$USER!=“hudson”]
然后
echo“您不能将内容提交到主分支”
echo“要更正此运行”
echo“git重置--软头^”
echo“git分支-c然后运行”
回音“git推送”
echo“如果通过测试,hudson会把它推给master”
出口1;
其他的
echo“我是哈德逊,允许提交给master”
fi
完成
这里有类似的答案,但有两个脚本

#!/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