GitLab CI-CD 推送到存储库¶
在 gitlab-runner 上将更改推送到存储库。
我们假设使用HTTPS方法访问存储库。
1.为项目添加个人访问令牌(PAT)确保此令牌具有权限write_repository。¶
2. 将变量添加到项目中我们假设变量名称是GITLAB_PRIVATE_TOKEN,值是第一步创建的令牌。¶
3. 构建您的.gitlab-ci.yml使用适当的权限更新 git url:git remote set-url origin "https://${GITLAB_PRIVATE_TOKEN}@gitlab.com/${CI_PROJECT_PATH}.git"¶
.gitlab-ci.yml看起来像:```
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/\).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 配置