目录
复盘Jenkins的安装到项目构建调通
前言
之前有一篇文章大概的讲了一下Jenkins的安装配置,但是那篇文章的诞生背景比较特殊,原本是糊弄上级的文档,不够实在,还有一个原因,这个上级技术不过关,还整天喜欢哔哔赖赖,不干实事,这些都是题外话,吐槽一波。
安装
- 首先要注意版本
笔者安装的是2.315配合java8使用,但是此版本有个小bug,在部署中的项目可能不会显示进度,需要刷新页面,可以尝试一下其他版本;除此之外,得注意一下jenkins的版本和java的版本,从某个版本开始最低的java版本为11,具体哪个版本,请自行百度。
ps:请安装前配置好java8环境变量 - 详细的安装教程
- 下载位置:
https://mirrors.jenkins-ci.org/redhat/ - 参考教程:
https://www.jianshu.com/p/718efc41f6c3
https://www.cnblogs.com/szx666/p/16145096.html
https://blog.51cto.com/u_11639179/3253155
有几个要注意的地方:
首先请把JENKINS_USER设置为root,防止后面的权限不够,忘了更改也没事,后面也有其他办法(为jenkins增加root权限好像不太行);然后是配置jdk的路径不生效,原因嘛,怎么百度也没用,请将你的路径放在候选的最上层位置,就生效了,俺也是没办法才试出来的;解锁jenkins时,请选择安装推荐的插件,免得后面手动安装 - 卸载教程,请用命令卸载(不要自己去到处找文件执行rm -rf,这样删不干净):
https://blog.csdn.net/Sumuxi9797926/article/details/124972910
- 需要安装的插件、jenkins配置和编写shell脚本
请参考俺的另一篇博客,偷个懒,不重复写啦,不过,最新的脚本已经变啦,是为了将日志挂载出来改的脚本,这里贴一下:
#!/bin/bash -il
#maven打包
mvn clean package -Dmaven.test.skip=true
echo 'package ok!'
echo 'build start!'
# cd ./
service_name="administrate"
service_prot=8070
log_address="/workplat/logs/logback/admin"
mount_address="/mydata/app/logs/admin"
echo "mount_address $mount_address"
#查看镜像id
IID=$(docker images | grep "$service_name" | awk '{print $3}')
echo "IID $IID"
if [ -n "$IID" ]
then
echo "exist $service_name image,IID=$IID"
#删除镜像
docker rmi -f $service_name
echo "delete $service_name image"
#构建
cd administrate/
docker build -t $service_name .
echo "build $service_name image"
else
echo "no exist $service_name image,build docker"
#构建
cd administrate/
docker build -t $service_name .
echo "build $service_name image"
fi
#查看容器id
CID=$(docker ps | grep "$service_name" | awk '{print $1}')
echo "CID $CID"
if [ -n "$CID" ]
then
echo "exist $service_name container,CID=$CID"
#停止
docker stop $service_name
#删除容器
docker rm $service_name
else
echo "no exist $service_name container"
fi
#启动
cd /
echo "启动语句 docker run -d --name $service_name --net=host -p $service_prot:$service_prot -v $mount_address:$log_address $service_name"
docker run --privileged=true -d --name $service_name --net=host -p $service_prot:$service_prot -v $mount_address:$log_address $service_name
#查看启动日志
# docker logs -f -t --tail 100 $service_name
#!/bin/bash -il
#maven打包
mvn clean package -Dmaven.test.skip=true
echo 'package ok!'
echo 'build start!'
# cd ./
service_name="business"
service_prot=8060
log_address="/workplat/logs/logback/business"
mount_address="/mydata/app/logs/business"
echo "mount_address $mount_address"
#查看镜像id
IID=$(docker images | grep "$service_name" | awk '{print $3}')
echo "IID $IID"
if [ -n "$IID" ]
then
echo "exist $service_name image,IID=$IID"
#删除镜像
docker rmi -f $service_name
echo "delete $service_name image"
#构建
cd business/
docker build -t $service_name .
echo "build $service_name image"
else
echo "no exist $service_name image,build docker"
#构建
cd business/
docker build -t $service_name .
echo "build $service_name image"
fi
#查看容器id
CID=$(docker ps | grep "$service_name" | awk '{print $1}')
echo "CID $CID"
if [ -n "$CID" ]
then
echo "exist $service_name container,CID=$CID"
#停止
docker stop $service_name
#删除容器
docker rm $service_name
else
echo "no exist $service_name container"
fi
#启动
cd /
echo "启动语句 docker run -d --name $service_name --net=host -p $service_prot:$service_prot -v $mount_address:$log_address $service_name"
docker run --privileged=true -d --name $service_name --net=host -p $service_prot:$service_prot -v $mount_address:$log_address $service_name
#查看启动日志
# docker logs -f -t --tail 100 $service_name
rm -rf node_modules/
rm -rf yarn.lock
rm -rf package-lock.json
npm cache clean --force
npm cache verify
echo "运行 npm install"
jenkins_shell_path=$(pwd)
echo "jenkins_shell_path: $jenkins_shell_path"
npm install
npm i --unsafe-perm
echo "运行 run build"
npm run build
echo "构建成功"
rm -rf /www/workplat-front/
mkdir -p /www/workplat-front/
mv ./dist/* /www/workplat-front/
- 遇到的问题归总
- 循环依赖(mina sshd导致的)
解决方法:当我选了一些第三方插件,其中包括mvn的,重启Jenkins,直接GG(这些插件全部加载失败),网上没有任何解决办法,全靠自己摸索,这里真的直接想骂人了,手动改安装低版本的mina sshd即可解决。
插件下载地址:http://mirror.xmission.com/jenkins/plugins/maven-plugin/ - Got permission denied while trying to connect to the Docker daemon socket at(Jenkins启动docker权限不足)
原因:这应该就是之前JENKINS_USER没有设置为root导致的问题
https://www.cnblogs.com/ding2016/p/12988080.html
https://huaweicloud.csdn.net/63310f76d3efff3090b50c25.html?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2defaultBlogCommendFromBaiduactivity-8-125384351-blog-110479644.pc_relevant_recovery_v2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultBlogCommendFromBaiduactivity-8-125384351-blog-110479644.pc_relevant_recovery_v2&utm_relevant_index=9
https://blog.csdn.net/weixin_42447403/article/details/123796067
https://cloud.tencent.com/developer/article/2051230
解决方法:
https://www.codenong.com/cs110479644/
https://blog.csdn.net/weixin_42447403/article/details/123796067
https://blog.csdn.net/weixin_34062329/article/details/86445001?spm=1001.2101.3001.6650.11&utm_medium=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-11-86445001-blog-110479644.pc_relevant_recovery_v2&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2defaultCTRLISTRate-11-86445001-blog-110479644.pc_relevant_recovery_v2&utm_relevant_index=12