Gitlab returning remote: You do not have permissions to do this.在执行脚本 git 推送时

Gitlab returning remote: You do not have permissions to do this. while performing scripted git push

我的场景如下:

我们为我们的团队设置了一个 gitlab,我们在其中使用分支等进行所有开发。我们还有一个由我们公司托管的官方回购,我们希望在其中镜像我们的主分支,以便人们(可以访问我们公司的这个 repo)可以查看我们的代码。

我写了一个 post-receive 钩子,它将镜像提交到 gitlab 上的主分支到官方 repo:(/opt/gitlab/embedded/service/gitlab-shell/hooks/post-receive 在 gitlab 上)

#!/opt/gitlab/embedded/bin/ruby
# Fix the PATH so that gitlab-shell can find git-upload-pack and friends.
ENV['PATH'] = '/opt/gitlab/bin:/opt/gitlab/embedded/bin:' + ENV['PATH']

#!/usr/bin/env ruby

# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.
#
deveo_server="deveo@deveo.XXXX.com:XXXX/projects/XXXX/repositories/git/Project"

from, to, branch = ARGF.read.split " "
if (branch =~ /master$/) == nil
    puts "Received branch #{branch}, not deploying."
    exit
end

`git remote add deveo #{deveo_server} >/dev/null 2>&1`
`git push deveo master`
 puts "DEPLOY: master(#{to}) mirrored to '#{deveo_server}'"

refs = ARGF.read
key_id  = ENV['GL_ID']
repo_path = Dir.pwd

require_relative '../lib/gitlab_custom_hook'
require_relative '../lib/gitlab_post_receive'

if GitlabPostReceive.new(repo_path, key_id, refs).exec &&
    GitlabCustomHook.new.post_receive(refs, repo_path)
  exit 0
else
  exit 1
end

问题是,当我这样做时,我收到以下提交到 gitlab 主分支的信息:

[master aa4a4f2] testing hooks 7
 0 files changed
 create mode 100644 testing_hooks_7
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 264 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: You do not have permissions to do this.
remote: fatal: Could not read from remote repository.
remote: 
remote: Please make sure you have the correct access rights
remote: and the repository exists.
remote: DEPLOY: master(aa4a4f218b7bc335ee3e0d6d52df5cfd5ddc1c99) mirrored to 'deveo@deveo.XXXX.com:XXXX/projects/XXXX/repositories/git/Project'
To git@projectgitlab.net:XXXX/Project.git
   1e92695..aa4a4f2  master -> master

我已经在那里启动了 ssh 代理,并将 git 用户的 ssh 从 gitlab 添加到 deveo,但是缺少一些东西。

当我在本地计算机上的本地存储库旁边使用裸存储库设置它时,这已经起作用了 - 所以必须在某处丢失一些密钥..但是在哪里:(?

好的,问题是我创建的机器人(在 deveo 中)是一个 read-only 机器人。我需要去 project options->Settings and bot accounts->bot->give this bot write permissions to repositories.

当然,我需要将 git 用户 ssh 密钥(来自 gitlab 的主机)添加到 deveo。

现在一切正常:)