Push files to gitlab-ci via CI runner

Venkat picture Venkat · Oct 19, 2016 · Viewed 19k times · Source

I am using gitlab CI runner to test my code and generating some files. I just want to push the generated files to gitlab repository via CI runner. Is there any way to do that ?

Answer

jmuhire picture jmuhire · Apr 24, 2018

I have resolved this issue by doing this :

  1. Generate new gitlab access token with api scope : User Settings > Access Tokens
  2. Add a protected CI variable into your project settings with the new token : Your project > Settings > Secret variable

-> edit : If you want to git push to a non protected branch do not set the runner variable as protected

Then you can use this token instead of the default in you gitlab-ci script. for example :

before_script:
  - git remote set-url origin https://USERNAME:${CI_PUSH_TOKEN}@gitlab.com/your-project.git
  - git config --global user.email '[email protected]'
  - git config --global user.name 'yourname'

...

- git checkout -B branch
- change files
- git commit -m '[skip ci] commit from CI runner'
- git push --follow-tags origin branch