一、安装
这是我从网上down的一张图片,感觉说的很全,jenkins相关操作全都可以应付了!
注意:对jdk版本有要求
https://pkg.jenkins.io/redhat/
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
yum install jenkins
启动
service jenkins start
卸载
rpm -e jenkins
#是否卸载成功
rpm -ql jenkins
#删除残留
find / -iname jenkins | xargs -n 1000 rm -rf
二、配置及使用
1. 本地执行
以执行shell命令为例,配置docker项目,创建一个自由风格项目
配置git密钥
添加参数
添加仓库
添加shell命令
#!/bin/bash -ilex
ls
cd $module
ls
gradle clean build -x test
docker rm -f $module || true
docker rmi -f 49.234.11.236:5000/only-class/$module:latest || true
docker build -t 49.234.11.236:5000/only-class/$module:latest .
if [ $module = web-api ];then
docker run --name $module -d -p 8881:8080 -v /data/logs/oc-api-v2:/app/log -e SPRING_PROFILES_ACTIVE=dev 49.234.11.236:5000/only-class/$module:latest
elif [ $module = admin-api ];then
docker run --name $module -d -p 8882:8080 -v /data/logs/oc-api-v2:/app/log -e SPRING_PROFILES_ACTIVE=dev 49.234.11.236:5000/only-class/$module:latest
else
docker run --name $module -d -p 8883:8080 -v /data/logs/oc-api-v2:/app/log -e SPRING_PROFILES_ACTIVE=dev 49.234.11.236:5000/only-class/$module:latest
fi
if [ $nexus = push ];then
docker login 49.234.11.236:5000 -u admin -p OnlyOnline@2020
docker push 49.234.11.236:5000/only-class/$module:latest
else
ls
fi
效果
2. 远程执行
一般本地构建成功的项目(dev)都要推送到远端(uat,prod)布署,下面以docker推送及远程发布为例
安装SSH插件
在插件管理里搜索“SSH”并安装
配置SSH密钥
配置SSH HOSTS
添加远程shell命令
这里要选择远程host shell,其它正常创建就行了
三、问题
1. shell脚本执行docker没有权限
打开配置文件
vim /etc/sysconfig/jenkins
修改$JENKINS_USER="root"
重启service jenkins restart
2. 启动出错
查看报错信息 service jenkins start
,找不到java
我的问题是jdk版本不支持11
从官网下载jdk1.8解压到相应的目录/opt/jdk1.8.0_271/
修改/etc/init.d/jenkins
,然目录配置好
执行systemctl daemon-reload
然后再执行service jenkins start
成功