Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

committing to repository as part of CI build

Tags:

gitlab-ci

I have a CI pipeline that is likely doing something semi-perverted. Let's not debate that part.

As part of the CI, I will generate an artifact (README.md) which I would like to commit and push back to the same repository. Simply using git push origin ... doesn't work due to authentication error.

Am I constrained to using something like a secret variable and a token, and adding another remote so that it can push?

like image 348
Chris Cleeland Avatar asked Dec 22 '16 20:12

Chris Cleeland


People also ask

Is GitHub part of CI CD?

CI/CD and workflow automation are native capabilities on GitHub platform. Here's how to start using them and speed up your workflows. The first time I saw a CI/CD pipeline in action was a real wake-up moment.

Can GitHub be used for CI?

CI using GitHub Actions offers workflows that can build the code in your repository and run your tests. Workflows can run on GitHub-hosted virtual machines, or on machines that you host yourself. For more information, see "About GitHub-hosted runners" and "About self-hosted runners."

How do I push a Git repository to another repository?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.


1 Answers

There are ways to add a ssh token to your build runtime which is able to commit or even do a push to origin. I think even recently GitLab added a new functionality that for each build a unique token is generated which can be used for same sake.

However in general I dont think you can commit anything on the same git base that build is running on, as the check out is in a detached head mode. This means you will not be able to add to history, specially in a remote.

Next problem to consider is what this means if you were able to commit back for the build system, which can potentially trigger another build and a cycle will be triggered.

So probably either use the artifact system for it or do add the ssh token and clone/checkout/commit/push in a separate directory during the build. Anyway this doc explains how to add the token: https://docs.gitlab.com/ee/ci/ssh_keys/README.html

like image 98
mohamnag Avatar answered Oct 05 '22 13:10

mohamnag