jenkins依赖包全家桶(maven、jdk、jenkins):
https://download.csdn.net/download/YouShouRenSheng/87791333
1、首先安装JDK 最低版本8.0
命令:yum -y install java-1.8.0-openjdk-devel
验证:java -version
2、安装Jenkins步骤
①添加Jenkins源
1)sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
2)sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
②通过yum命令安装Jenkins
sudo yum -y install jenkins
碰到问题:jenkins-2.222.4-1.1.noarch.rpm FAILED
解决方法: 参考链接 centos安装jenkins简要过程及出现的问题(一)_追梦-北极星的博客-CSDN博客
一、centos安装jenkins的rpm安装包分为yum安装和rpm安装已经下载好的jenkins包
jenkins安装包的下载路径:jenkins个版本的rpm安装包,下面主要说明rpm安装的流程:
1)获取rpm安装包的的地址,安装包:jenkins-2.213-1.1.noarch.rpm,如下在centos获取安装包下载命令:
wget https://prodjenkinsreleases.blob.core.windows.net/redhat/jenkins-2.213-1.1.noarch.rpm
2)安装下载好的rpm包
sudo rpm -ivh jenkins-2.213-1.1.noarch.rpm
③配置jenkins的端口,设置为:8085
nohup /home/h3c/jdk/java/bin/java -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8085 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20 &
④启动jenkins服务
sudo service jenkins start
3、配置jenkins服务
1) 在浏览器访问jenkins页面
http://localhost:8085/
2)根据页面提示位置/var/lib/jenkins/secrets/initialAdminPassword,获取初始密码
命令:cat /var/lib/jenkins/secrets/initialAdminPassword
前端vue项目参考这个:
https://download.csdn.net/download/YouShouRenSheng/87791338
后端springboot项目参考这个:
https://download.csdn.net/download/YouShouRenSheng/87791343
Jenkins所在主机和远程如果不是一台机器,需要做免密配置。
免密配置操作步骤:
1、修改ssh配置
# 每台linux主机修改配置文件/etc/ssh/sshd_config
$ vi /etc/ssh/sshd_config
#启用这三项配置,即去掉这三项的注释
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
2、生成公私钥
#在源主机上执行 生成公私钥对
$ ssh-keygen -t rsa -P ''
# 查看生成的公私钥
$ cd /root/.ssh/
$ cp id_rsa.pub authorized_keys
id_rsa: 私钥
id_rsa.pub: 公钥
3、安装到目标主机
$ scp /root/.ssh/id_rsa.pub [email protected]:/root/.ssh/;
$ scp /root/.ssh/authorized_keys [email protected]:/root/.ssh/;
4、测试免密登录
ssh [email protected];
4.1、后端构建命令参考
md5sum /root/.jenkins/workspace/epidemic_yantai_test/target/epidemic_service-1.0.jar
scp -P 22222 /root/.jenkins/workspace/epidemic_yantai_test/target/epidemic_service-1.0.jar 172.168.1.223:/opt/h3c/apps/report_service/report_service.jar
ssh -p 22222 [email protected] "md5sum /opt/h3c/apps/report_service/report_service.jar "
ssh -p 22222 [email protected] "sh /opt/h3c/apps/report_service/restart.sh "
4.2、前端构建命令
cd /root/.jenkins/workspace/epidemic_yantai_web_test
#npm config set registry https://registry.npm.taobao.org
#npm install
npm run build #打包
cd web
rm -rf web.zip #删除上次打包生成的压缩文件
zip -r web.zip ./web
md5sum /root/.jenkins/workspace/epidemic_yantai_web_test/web/web.zip
scp -P 22222 /root/.jenkins/workspace/epidemic_yantai_web_test/web/web.zip 172.168.1.223:/opt/h3c/apps/report_web/report_web\@tomcat/webapps/web.zip
ssh -p 22222 [email protected] "md5sum /opt/h3c/apps/report_web/report_web\@tomcat/webapps/web.zip "
ssh -p 22222 [email protected] "mv /opt/h3c/apps/report_web/report_web\@tomcat/webapps/web /opt/h3c/apps/report_web/report_web\@tomcat/webapps/web$(date +%Y%m%d%H%M%S)"
ssh -p 22222 [email protected] "unzip -o -d /opt/h3c/apps/report_web/report_web\@tomcat/webapps/ /opt/h3c/apps/report_web/report_web\@tomcat/webapps/web.zip"
ssh -p 22222 [email protected] "rm -rf /opt/h3c/apps/report_web/report_web\@tomcat/webapps/web.zip "