GitLab CI/CD 學習記錄 - 問題匯總
一、gitlab-runner 權限
#卸載runner配置 sudo gitlab-runner uninstall #以root用戶重裝runner配置,--user 要配置的用戶 #建議:新建用戶,付用戶相應的權限,例如docker,k8s集群操作權限..... gitlab-runner install --working-directory /home/gitlab-runner --user root #最后重啟 sudo service gitlab-runner restart
二、git 版本升級
gitlab CI 失敗一次后 fatal: git fetch-pack: expected shallow list
原因:git版本太老不持之新API;
解決方案:需要升級一下git。
git --version yum -y remove git yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm yum -y install git git --vresion
三、sshpass 安裝
yum -y install sshpass
四、 docker login 登錄 harbor 倉庫報錯
[gitlab-runner@ecs-aece .ssh]$ docker login xx.xx.xx.xxx
Username: admin
Password:
Error response from daemon: Get https://xx.xx.xx.xxx/v2/: dial tcp xx.xx.xx.xxx:443: connect: connection refused
原因:用http部署的harbor,這里是https://進行訪問的,所以出現報錯
解決:
在 /etc/docker/daemon.json 文件中,添加對私有倉庫的認證,然后重啟 docker。
{ "insecure-registries":["172.17.8.201:8003"] }
注意:如果 harbor 也在該機器上,則 harbor 也需要重啟。
五、內網地址
阿里雲服務器之間 用內網 ip 訪問速度比較快,用公網 ip 訪問非常慢。
六、腳本變量
在 .gitlab-ci.yml 中定義的變量,直接賦值 只能使用一次。如:
A = “the value”
B = $A
C = $B # 此時 C 取不到 “the value” 的值。
七、jar包 沒有包含主清單錯誤
no main manifest attribute, in /app.jar
原因:
解決方案:修改 pom.xml 中的 build plugin 部分
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!--加入下面兩項配置--> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> <configuration> <includeSystemScope>true</includeSystemScope> </configuration> </plugin>
八、清除無用的 docker 鏡像及容器
docker system prune -a -f; # 刪除所有未被 tag 標記和未被容器使用的鏡像:
九、shell腳本權限
[root@dev-platform shells]# ls build.sh deploy-dev.sh [root@dev-platform shells]# [root@dev-platform shells]# chmod +x build.sh [root@dev-platform shells]# chmod +x deploy-dev.sh [root@dev-platform shells]# ls build.sh deploy-dev.sh [root@dev-platform shells]#
shell 可執行 環境變量配置路徑
export PATH=/home/gitlab-runner/shells:$PATH
十、shell腳本執行錯誤 $'\r':command not found
原因:因為 編寫的 shell腳本是在win下編寫的,每行結尾是\r\n 的Unix 結果行是\n 所以在Linux下運行腳本 會任務\r 是一個字符,所以運行錯誤,需要把文件轉換下。
解決方案:
方法1:sed -i 's/\r//' 腳本名稱
sed -i 's/\r//' build.sh && bash build.sh
方法2:
yum -y install dos2unix
dos2unix 腳本名
參考資料:
GitLab CI/CD +Shell腳本實現簡單的自動代碼部署+重新啟動dotnet 服務
docker運行spring boot 包鏡像出現no main manifest attribute問題