情況說明:
一台主機上使用yum方式安裝的gitlab,使用docker方式安裝的gitlab-runner
主機上的/etc/hosts添加了一條自定義的解析域名
192.168.80.201 gitlab.example.com
windows客戶端上的hosts文件也添加了這個。
gitlab的配置文件/etc/gitlab/gitlab.rb中有關設置如下
cat /etc/gitlab/gitlab.rb|grep external_url | grep -v "^#"
external_url 'http://gitlab.example.com'
/var/opt/gitlab/gitlab-rails/etc/gitlab.yml
文件中顯示的也是
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: gitlab.example.com
port: 80
https: false
這樣一來的結果是項目中克隆的地址都是使用的gitlab.example.com,同時gitlab-runner上添加的話顯示的url地址也是gitlab.example.com
windows客戶端上使用瀏覽器訪問這個域名可以打開並登錄gitlab上,同時也可以創建項目往gitlab上推送拉取等。
但是結合gitlab-runner使用的時候,新建了一個.gitlab-ci.yml
文件,想實現windows客戶端這邊提交代碼到gitlab上后,直接開始CICD功能。
但是在執行CICD功能的時候,提示沒法解析gitlab.example.com這個域名
就算把用容器起來的docker-runner的網絡換成host方式,采用宿主機的/etc/hosts配置后還是出現上述同樣的問題。
臨時解決辦法,修改/var/opt/gitlab/gitlab-rails/etc/gitlab.yml
文件中host為gitlab所在主機ip
## GitLab settings
gitlab:
## Web server settings (note: host is the FQDN, do not include http://)
host: 192.168.80.201
port: 80
https: false
這樣一來拉取代碼的話使用的就是ip地址。
問題分析:
在執行pipeline job的時候,gitlab runner會使用指定的image臨時build一個container來執行job,那么首先在container中會先pull你的project的代碼,但是使用默認的橋接網絡沒法訪問到gitlab.example.com對應的地址
解決辦法:
在gitlab-runner配置文件中添加額外的域名解析,在運行時拉取gitlab上的倉庫文件時需要使用的,在 [runners.docker] 下
添加多個的示例:
[runners.docker]
extra_hosts = ["gitlab.example.com:192.168.80.201","jdd.io:192.168.2.162"]