0
  • I am using GITLAB to deploy a script that pull information from a bunch of cisco switches, process these information and put them on an excel file to be more representable.

  • I am using CI-CD on gitlab with a docker runner that initiate an ubuntu image. Once this image is initiated. It pulls my master repository, execute the script and finaly generate my excel file (which already exist on my repository).

  • This script is successfully excecuted.

My question is how to update the excel file on my master repo with that new excel file that just have been generated on my docker appliance initiated with my gitlab runner??

Thanks,

  • 1
    You can refer this question [How do I push to a repo from within a gitlab CI pipeline](https://stackoverflow.com/questions/51716044/how-do-i-push-to-a-repo-from-within-a-gitlab-ci-pipeline) – antoniomerlin Apr 04 '21 at 15:00

1 Answers1

0

All right, I might be slightly late but I'm hyped up for my first contribution!

Since you are already pulling from your repo, this should be somewhat straightforward, since you have probably already added some ID access. In case you haven't, you can create an Access Token with write_repository rights. Add this token to your CI/CD Variables in the project's settings (let's name it GIT_PUSH_TOKEN) Also, you'll need to install Git on your Ubuntu image.

Inside your pipeline, you'll insert the usual sequence of commands to push, which can be done in an anchor - remember that first you have to configure the Git user, in this case, the GitLab runner.

In the end, you'd have a script somewhat like this:

variables:
  BRANCH_NAME: "feature-gitlab-ci"
  BOT_NAME: "GitLab Runner Bot"
  BOT_EMAIL: "gitlab-runner-bot@example.net"
  COMMIT_MESSAGE: "Commit from runner "

stages:
 - push_excel_file

.push: &push |
  git config --global user.name "${BOT_NAME}"
  git config --global user.email "${BOT_EMAIL}"
  git add EXCEL_FILE.xlsx
  git commit -m "${COMMIT_MESSAGE} ${CI_RUNNER_ID}"
  git push -o ci.skip "https://whatever:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}" $BRANCH_NAME

push_excel_file:
  stage: push_excel_file
  image: ubuntu:rolling
  before_script:
    - apt-get update
    - apt-get install git -y
    - git fetch
    - git checkout $BRANCH_NAME
  script:
    - *push

ATM, whatever in the url is really whatever for what really counts is the Access Token.

BTW: this answer wouldn't have been possible if not for the legend in the following link: https://parsiya.net/blog/2021-10-11-modify-gitlab-repositories-from-the-ci-pipeline/

So catch up with him if there are still doubts. Peace!

Torxed
  • 22,866
  • 14
  • 82
  • 131