【发布时间】:2019-07-10 07:39:31
【问题描述】:
我在运行 shell 脚本时遇到问题,该脚本基本上将目录中的更改从另一个脚本中提交到远程 git 存储库。 “超级脚本”正在以超级用户权限运行,并且我在超级用户的主目录中的 ~/.ssh/ 处生成了所需的 ssh 密钥。此外,独立运行内部脚本可以正常运行并推送到远程存储库。
这是我在运行超级脚本时遇到的错误:
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 326 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to push code to protected branches on this project.
To git@url.goes.here:groupspace/projectspace.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@url.goes.here:groupspace/projectspace.git'
我用这行代码调用内部脚本,保存其退出状态以供进一步处理
SUCCESS = $(bash /path/to/push-config.sh)
这是push-config.sh的内容
#!/bin/bash
#
stamp=$(date +"%Y-%m-%d %T")
git add .
git commit -m "Config $stamp"
if [ $? -eq 0 ]
then
git push -u origin master
if [ $? -eq 0 ]
then
echo "Successfully pushed config to repo."
exit 0
else
echo "Failure while pushing to repo."
exit 1
fi
else
exit 1
fi
任何帮助表示赞赏,在此先感谢。
【问题讨论】:
-
running the inner script standalone works fine: 你是以超级用户/root 运行它吗?也许显示你的 push-config.sh 也可能有帮助 -
@ikkentim 是的,我以 root 身份运行它,一切正常。将添加 push-config.sh
-
这是错误“remote: GitLab: You are not allowed to push code to protected branches on this project.”
-
@vorac 我知道这是错误,但我不知道为什么会得到它。我可以将代码推送到上述项目的受保护分支,我有必要的密钥,并且脚本本身运行良好。