- Ensure you have runners available to run your jobs. GitLab SaaS provides runners, so if you’re using GitLab.com, you can skip this step.
If you don’t have a runner, install GitLab Runner and register a runner for your instance, project, or group.
- Create a .gitlab-ci.yml file at the root of your repository. This file is where you define your CI/CD jobs.
Use special characters with
script
- 错误描述(类似如下):
$ git submodule update --init --recursive
Submodule 'lib/urlgrabber' (git@gitlab.colynn.com:linux/urlgrabber.git) registered for path 'lib/urlgrabber'
Cloning into 'lib/urlgrabber'...
Host key verification failed.
fatal: Could not read from remote repository.
- 解决方案: 方案1)使用相对路径:I had to change the paths in .gitmodules to relative
[submodule "lib/urlgrabber"]
path = lib/urlgrabber
- url = git@gitlab.deif.com:linux/urlgrabber.git
+ url = ../../linux/urlgrabber.git
方案2)通过前置脚本修改git config
替换掉git@gitlab.colynn.com:linux/urlgrabber.git
a. 通过为gitlab-ci.yml
添加before_script
的方式实现替换
before_script:
- git config --global --add url."https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@gitlab.colynn.com/linux/urlgrabber.git".insteadOf "git@gitlab.colynn.com:linux/urlgrabber.git"
b. 通过runner
的配置文件,添加pre_clone_script
的方式实现替换
pre_clone_script="git config --global --add url.\"https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@gitlab.colynn.com/linux/urlgrabber.git\".insteadOf \"git@gitlab.colynn.com:linux/urlgrabber.git\"\n"