前因:gitlab替换成https后,CI报错,SSL connect error,gitlab默认使用http方式克隆代码,而CI服务器是centos6.5,未找到升级SSL库之类的方法;发现使用SSH克隆代码可行,找到的方法如下:
Gitlab Runner配置中并没有直接修改克隆代码方式的配置,只能禁用默认方式,并自行添加克隆代码脚本;
在config.toml中添加配置:
[[runners]]
# [...]
environment = ["GIT_STRATEGY=none"]
pre_build_script = '''
# Fetching using ssh (via pre_build_script in config.toml)
if [ -d "${CI_PROJECT_DIR}" ]; then rm -rf "${CI_PROJECT_DIR}"; fi
mkdir -p "${CI_PROJECT_DIR}"
cd "${CI_PROJECT_DIR}"
git init
git remote add origin "ssh://git@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
git fetch origin "${CI_COMMIT_SHA}"
git reset --hard FETCH_HEAD
'''
# [...]
CI_SERVER_HOST需自行配置或直接替换为自己的gitlab地址;
https://docs.gitlab.com/14.10/runner/configuration/advanced-configuration.html
https://stackoverflow.com/questions/39208420/how-do-i-enable-cloning-over-ssh-for-a-gitlab-runner
评论区