Add Files To The Repo Using Gitlab Ci Cd

Viewed 1592

I am using Gitlab to serve http file server, which contains asset files for game that I'm working on. When you start the game the application checks if you have already download the asset files or not and it supposed to support asset updates to.

For the update system I want that the app will check the sha of the asset file for each one, and if it different from the sha of the local file, the file will be replaced.

Is it possible to create a CI/CD job that will write the sha of all the files in the repo to file and push this file into the repo itself, so the app can download also the file that contains the sha values?

Thank alot!!

1 Answers

First you need is a git package in your container/shell runner.

Example: You need to push to other repo:

  1. clone repo to runner
  2. add alias_link to remote repo
  3. add files to git
  4. commit them
  5. push to remote repository by alias_link.

Put these standard git commands to gitlab-ci job script:

git_job:
  image: alpine
  script:
    - apk add git
    - git clone https://oauth2:${PRIVATE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}.git
    - git remote add alias_link https://oauth2:${PRIVATE_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}.git
    - git config user.name "WhoCareS"
    - git config user.email "CiContributor@email.com"
    - git add your_file1
    - git add yourdir1/
    - git commit -m "yay! new files!"
    - git push -u alias_link

If you need to push to the same repo the job has started, you can skip first step with cloning.

Related