GitLab CI-CD Push to Repository
On gitlab-runner push changes to repository.
We assume that accessing repository with HTTPS method.
1. Add Personal Access Token (PAT) for Project
Section titled “1. Add Personal Access Token (PAT) for Project”Ensure this token have the authority write_repository.
2. Add Variable to Project
Section titled “2. Add Variable to Project”We assume that the variable name is GITLAB_PRIVATE_TOKEN, and value is the token created in first step.
3. Construct your .gitlab-ci.yml
Section titled “3. Construct your .gitlab-ci.yml”Update git url with proper authority:
git remote set-url origin "https://${GITLAB_PRIVATE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git"
The .gitlab-ci.yml looks like:
stages: - build - deploy
build: stage: build script: - echo "Building your application..."
deploy: stage: deploy before_script: - git remote set-url origin "https://${GITLAB_PRIVATE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git" script: - echo "Deploying your application..." - git add . - git commit -m "Automated commit by GitLab CI/CD" - git push origin[1]. GitLab-CI-CD-with-GitLab-Runner
[2]. Git-Configuration