Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push files to gitlab-ci via CI runner

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 ?

like image 829
Venkat Avatar asked Oct 19 '16 05:10

Venkat


1 Answers

I have resolved this issue by doing this:

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

  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 using variable name CI_PUSH_TOKEN
  3. Add another protected CI variable with your username using variable name CI_USERNAME

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://${CI_USERNAME}:${CI_PUSH_TOKEN}@gitlab.com/${CI_PROJECT_NAME}.git   - git config --global user.email '${GITLAB_USER_EMAIL}'   - git config --global user.name '${GITLAB_USER_ID}'  ...  - git checkout -B branch - # do the file changes here - git commit -m '[skip ci] commit from CI runner' - git push --follow-tags origin branch 
like image 92
jmuhire Avatar answered Sep 20 '22 09:09

jmuhire