jenkins中文社区
https://www.jenkins.io/zh/doc/book/installing/
1、系统管理
#邮件内容模板文档:https://blog.csdn.net/J_____Q/article/details/118518554
#进行邮件测试,看是否可以收到邮件
#邮箱收件
2、全局工具配置
2.1、maven配置
(1)下载jdk1.8包,自行下载
(2)下载apache-maven-3.6.3包,官网地址:https://maven.apache.org/download.cgi
(3)maven配置文件修改
(4)设置环境变量
cat /etc/profile #最后添加,安装目录自定义 export JAVA_HOME=/data/jdk1.8.0_152 export MAVEN_HOME=/data/apache-maven-3.6.3 export PATH=$JAVA_HOME/bin:$PATH:$MAVEN_HOME/bin #刷新环境变量 source /etc/profile
(5)版本查看
(6)jenkins页面配置
#jdk
#git
#maven
3、全局安全配置(主要是用户访问项目控制)
4、创建任务
(1)首先创建文件夹,区分环境
(2)在test分支下新建任务
#Pipeline文件
pipeline { agent any //全局变量 environment{ BRANCH = "ruoyi-dev" } stages { //获取代码 stage('git pull') { steps { git branch: 'devops', credentialsId: 'dc2de64a-9639-4b92-abde-dd163b326691', url: '[email protected]:lipc/my-ruoyi.git' } } //java 打包 stage('mvn build') { steps { sh '''mvn clean mvn package -Dmaven.test.skip=true''' } } //打镜像 stage('image build') { steps { sh '''VERSION=$(cat version.txt | egrep -iw "version|[0-9]$" | head -1 | awk -F\'-\' \'{print $NF}\' | awk -F\'@\' \'{print $1}\') cp -f ./ruoyi-admin/target/ruoyi-admin.jar ./ docker login -u admin -p 11111 172.16.4.47:8090 docker build . -t 172.16.4.17:8090/${BRANCH}/ruoyi-server:${VERSION} docker push 172.16.4.17:8090/${BRANCH}/ruoyi-server:${VERSION} sed -i "s#hosts:.*#hosts: ${BRANCH}#g" ./ry.yml sed -i "s#branch:.*#branch: ${BRANCH}#g" ./ry.yml sed -i "s#version:.*#version: ${VERSION}#g" ./ry.yml ''' } } //部署服务 stage('devops service') { steps { sh '''ansible-playbook -i /etc/ansible/hosts ./ry.yml ''' } } } }
标签:git,部署,ruoyi,maven,BRANCH,jenkins,最新版,yml From: https://www.cnblogs.com/Leonardo-li/p/17303324.html