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问题