Commit Changes from CI job to branch


So I’m trying to set up a CI pipeline, and one of the things I’d like it to do is update the version numbers in some of my xml files and then commit those back to the branch. This CI pipeline is triggered when code is committed (usually by merge request) to my my ‘beta’ branch. Then one of the jobs updates the version numbers using a ruby script. Once everything passes I’d like to commit those version number updates up to the ‘beta’ branch but can’t seem to get it right. Here’s an iteration of the ruby script I’m using to try and commit the changes:

puts("# Commit changes to git")
system("git checkout beta")
system("git add #{@project_root}")
git_commit_msg = "[skip ci] beta version numbers updated"
system("git commit -m \"#{git_commit_msg}\"")
result = system("git push -f origin HEAD:beta") or raise "git push failed"

The user my CI runner works under has an ssh key to the repo and can commit changes just fine outside of the CI environment. But when this part runs I usually get:

remote: HTTP Basic: Access denied
fatal: Authentication failed for ‘http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@gitlabserver/owner/build-tools-sandbox.git/
/Users/usr/builds/daf17119/0/owner/build-tools-sandbox/tools/build-scripts/commit_changes.rb:41:in <class:Cleanup>': git push failed (RuntimeError) from /Users/usr/builds/daf17119/0/owner/build-tools-sandbox/tools/build-scripts/commit_changes.rb:7:in

and if you run the ruby script on the command line as the user that CI uses? ie outside of CI.

I’ve written quite a few ruby scripts and ran them all outside of the CI before trying to use them with CI, and they worked just fine.