Gitlab doesn't execute git during merge_action with environment PATH and GEM_PATH
Created by: pspoerri
-
Summary PATH and GEM_PATH are not forwarded to git commands on merge request. Thus producing a failure in the git hooks of the respective git repos
-
Steps
- Install gitlab with a 1.8 ruby as system ruby and 1.9.3 using rvm (or similar). Run gitlab with ruby 1.9.3
- Create an empty git repository
- Commit to repo, create branch
- Commit to new branch
- Push both branches to server
- Merge the two branches on gitlab
-
Expected behaviour The two branches should be merged, also see issues: https://github.com/gitlabhq/gitlabhq/issues/3349, https://github.com/gitlabhq/gitlabhq/issues/3706, https://github.com/gitlabhq/gitlabhq/issues/3714
-
Observed behaviour The git command is executed with the system ruby thus failing the gitlab-shell commit hook:
remote: /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2:in `require': no such file to load -- rubygems (LoadError) remote: from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/shared_helpers.rb:2 remote: from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/setup.rb:1:in `require' remote: from /usr/local/rvm/gems/ruby-1.9.3-p429@global/gems/bundler-1.3.5/lib/bundler/setup.rb:1 remote: error: hook declined to update refs/heads/master To /home/git/repositories/Spoerri/merge_request.git ! [remote rejected] master -> master (hook declined) error: failed to push some refs to '/home/git/repositories/Spoerri/merge_request.git'
-
Output of checks Gitlab Check:
git@svn:~/gitlab$ PATH="/usr/local/rvm/gems/ruby-1.9.3-p429@gitlab/bin:/usr/local/rvm/gems/ruby-1.9.3-p429/bin:/usr/local/rvm/gems/ruby-1.9.3-p429@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p429/bin:/usr/local/rvm/bin:/usr/bin:/bin" GEM_PATH="/usr/local/rvm/gems/ruby-1.9.3-p429@gitlab:/usr/local/rvm/gems/ruby-1.9.3-p429@global" bundle exec rake gitlab:check RAILS_ENV=production Checking Environment ... Git configured for git user? ... yes Has python2? ... yes python2 is supported version? ... yes Checking Environment ... Finished Checking GitLab Shell ... GitLab Shell version >= 1.4.0 ? ... OK (1.4.0) Repo base directory exists? ... yes Repo base directory is a symlink? ... no Repo base owned by git:git? ... yes Repo base access is drwxrws---? ... yes post-receive hook up-to-date? ... yes post-receive hooks in repos are links: ... Pascal Spörri / merge_request ... ok Checking GitLab Shell ... Finished Checking Sidekiq ... Running? ... yes Checking Sidekiq ... Finished Checking GitLab ... Database config exists? ... yes Database is SQLite ... no
-
Possible fixes I think it's sufficient to add the necessary environment variables to gitlab/lib/gitlab/satellite/merge_sction.rb . Since the merge command is executed by grit. Unfortunately the code below does not work:
def merge! env = {:PATH => ENV[:PATH], :GEM_PATH => ENV[:GEM_PATH]} in_locked_and_timed_satellite do |merge_repo| if merge_in_satellite!(merge_repo) # push merge back to Gitolite # will raise CommandFailed when push fails merge_repo.git.push({raise: true, timeout: true, env: env}, :origin, merge_request.target_branch) # remove source branch if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) # will raise CommandFailed when push fails merge_repo.git.push({raise: true, timeout: true, env: env}, :origin, ":#{merge_request.source_branch}") end # merge, push and branch removal successful true end end
As far as I see gitlab executes the Grit::Git::native command which has an option to set environment variables. Which however remains unset as far as I can test. Setting system ruby to ruby 1.9.3-pWHATEVER is not a solution.