1.安装Jenkins

  1. 下载最新的安装包 此处用的是 jenkins-2.346.2-1.1.noarch.rpm

下载地址是清华镜像:https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.346.2-1.1.noarch.rpm

  1. 进行安装 rpm -ivh jenkins-2.346.2-1.1.noarch.rpm
  2. 修改java 配置地址 和Jenkins 配置文件 中 端口用户名 jenkins 目录的地址
  3. 重新加载 参数 systemctl daemon-reload
  4. 启动Jenkins
  5. 进入到jenkins/updates 修改链接地址

sed -i ‘s#https://updates.jenkins.io/download#https://mirrors.tuna.tsinghua.edu.cn/jenkins#g’ default.json && sed -i ‘s#http://www.google.com#https://www.baidu.com#g’ default.json

  1. 安装推荐插件,再加入 Maven push SSH nodeJs 就行了
  2. 配置项目参数和git 地址 能拉下来就行

真实操作 极其恶心

1. 首先先Java8 安装 配置环境 不多说了 自行百度

2. 去清华源下载jenkins 的安装文件(就是快)
https://mirrors.tuna.tsinghua.edu.cn/jenkins/redhat-stable/?C=M&O=A

3. 然后 按照安装Jenkins 的教程 最新的版本教程有出入 
rpm -ivh  jenkins-2.346.2-1.1.noarch.rpm  

4. 修改Jenkins配置 端口,用户,主home地址 
vi /usr/lib/systemd/system/jenkins.service  
注意:网上很多到 /etc/sysconfig/jenkins 高版本不生效 见下文
https://blog.csdn.net/qq_41713884/article/details/123690713

5. 修改 java环境地址 
vim /etc/init.d/jenkins  

6. 用systemctl start jenkins 

环境问题导致的起不来:
1.在/etc/init.d/jenkins 中将本机的java 目录放到最上面 
2. 新增openjdk  配置
yum install fontconfig java-8-openjdk
3.创建一个软链接
ln -s /data/java/bin/java  /usr/bin/java
解决问题 恶心的来
安装JDK的时候看好版本 86 是32位的 日了狗
恶心到家了

总结 插件安装能用就行 低版本的jenkins 不好用 11的不符合项目 所以只能使用 我安装的版本了
但是出现了
this version of the Java Runtime only recognizes class file versions up to 52.0 报错 
我 又安装了一次 yum openjdk11 现在能拉下代码来了 坑很多 

2.安装Docker

https://blog.csdn.net/weixin_40461281/article/details/83153029
https://lionli.blog.csdn.net/article/details/111220320

3.安装harbor镜像私服仓库

{
  "registry-mirrors": ["http://hub-mirror.c.163.com"],
  "insecure-registries":["43.142.124.79:8060"],
  "graph": "/home/docker"
}

4.推送镜像到镜像仓库服务器

1.登录远程镜像仓库
docker login -u 用户名 -p 密码   仓库地址
docker login -u suiquantong -p Suiqt@123 43.142.124.79:7600
2.在项目中标记镜像:
docker tag SOURCE_IMAGE[:TAG] 43.142.124.79:7600/demo1/REPOSITORY[:TAG]
docker tag ruoyi/ruoyi-system:1.1.0 43.142.124.79:7600/demo1/ruoyi-system:1.1.0
3.推送镜像到远程仓库 项目下
docker push 仓库地址/项目名/镜像名称和版本
docker push 43.142.124.79:7600/demo1/REPOSITORY[:TAG]

5.若依PLUS文件上传到服务器

本人下拉镜像后,是通过docker-compose 进行打包的,所以需要将docker-compose.yml 文件上传到服务器上

version: '3'

services:
  mysql:
    image: mysql:8.0.29
    container_name: mysql
    environment:
      # 时区上海
      TZ: Asia/Shanghai
      # root 密码
      MYSQL_ROOT_PASSWORD: ruoyi123
      # 初始化数据库
      MYSQL_DATABASE: ry-cloud
    ports:
      - "3306:3306"
    volumes:
      # 数据挂载
      - /docker/mysql/data/:/var/lib/mysql/
      # 配置挂载
      - /docker/mysql/conf/:/etc/mysql/conf.d/
    command:
      # 将mysql8.0默认密码策略 修改为 原先 策略 (mysql8.0对其默认策略做了更改 会导致密码无法匹配)
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_general_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
    privileged: true
    network_mode: "host"

  nacos:
    image: nacos/nacos-server:v2.1.0
    container_name: nacos
    ports:
      - "8848:8848"
      - "9848:9848"
      - "9849:9849"
    environment:
      TZ: Asia/Shanghai
      MODE: standalone
      SPRING_DATASOURCE_PLATFORM: mysql
      MYSQL_SERVICE_HOST: 127.0.0.1
      MYSQL_SERVICE_PORT: 3306
      MYSQL_SERVICE_USER: root
      MYSQL_SERVICE_PASSWORD: ruoyi123
      MYSQL_SERVICE_DB_NAME: ry-config
      MYSQL_SERVICE_DB_PARAM: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    volumes:
      - /docker/nacos/logs/:/home/nacos/logs
      - /docker/nacos/config/custom.properties:/home/nacos/init.d/custom.properties
    privileged: true
    network_mode: "host"

  redis:
    image: redis:6.2.7
    container_name: redis
    ports:
      - "6379:6379"
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    volumes:
      # 配置文件
      - /docker/redis/conf:/redis/config
      # 数据文件
      - /docker/redis/data/:/redis/data/
    command: "redis-server /redis/config/redis.conf"
    privileged: true
    network_mode: "host"

  minio:
    image: minio/minio:RELEASE.2022-05-26T05-48-41Z
    container_name: minio
    ports:
      # api 端口
      - "9000:9000"
      # 控制台端口
      - "9001:9001"
    environment:
      # 时区上海
      TZ: Asia/Shanghai
      # 管理后台用户名
      MINIO_ACCESS_KEY: ruoyi
      # 管理后台密码,最小8个字符
      MINIO_SECRET_KEY: ruoyi123
      # https需要指定域名
      MINIO_SERVER_URL: ""
      # 开启压缩 on 开启 off 关闭
      MINIO_COMPRESS: "off"
      # 扩展名 .pdf,.doc 为空 所有类型均压缩
      MINIO_COMPRESS_EXTENSIONS: ""
      # mime 类型 application/pdf 为空 所有类型均压缩
      MINIO_COMPRESS_MIME_TYPES: ""
    volumes:
      # 映射当前目录下的data目录至容器内/data目录
      - /docker/minio/data:/data
      # 映射配置目录
      - /docker/minio/config:/root/.minio/
    command: server --address ':9000' --console-address ':9001' /data  # 指定容器中的目录 /data
    privileged: true
    network_mode: "host"

  ruoyi-seata-server:
    image: 43.142.124.79:8060/tyjr/ruoyi-seata-server:1.2.0
    container_name: ruoyi-seata-server
    ports:
      - "7091:7091"
      - "8091:8091"
    environment:
      TZ: Asia/Shanghai
      # 注意 此处ip如果是外网使用 要改为外网ip
      SEATA_IP: 43.142.241.220
      SEATA_PORT: 8091
      DUBBO_IP_TO_REGISTRY: 43.142.241.220
      # 注册到注册中心的端口
      DUBBO_PORT_TO_REGISTRY: 8091
      DUBBO_PORT_TO_BIND: 8091
    volumes:
      - /docker/ruoyi-seata-server/logs/:/ruoyi/seata-server/logs
    privileged: true
    network_mode: "host"

  nginx-web:
    image: nginx:1.21.6
    container_name: nginx-web
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "80:80"
      - "443:443"
    volumes:
      # 证书映射
      - /docker/nginx/cert:/etc/nginx/cert
      # 配置文件映射
      - /docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf
      # 页面目录
      - /docker/nginx/html:/usr/share/nginx/html
      # 日志目录
      - /docker/nginx/log:/var/log/nginx
    privileged: true
    network_mode: "host"

  sentinel:
    image: 43.142.124.79:8060/tyjr/ruoyi-sentinel-dashboard:1.2.0
    container_name: sentinel
    environment:
      TZ: Asia/Shanghai
    ports:
      - "8718:8718"
    volumes:
      # 配置文件
      - /docker/ruoyi-sentinel-dashboard/logs/:/ruoyi/sentinel-dashboard/logs
    restart: always
    network_mode: "host"

  ruoyi-monitor-admin:
    image: 43.142.124.79:8060/tyjr/ruoyi-monitor:1.2.0
    container_name: ruoyi-monitor
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "9100:9100"
    volumes:
      # 配置文件
      - /docker/ruoyi-monitor/logs/:/ruoyi/monitor/logs
    privileged: true
    network_mode: "host"

  ruoyi-xxl-job-admin:
    image: 43.142.124.79:8060/tyjr/ruoyi-xxl-job-admin:1.2.0
    container_name: ruoyi-xxl-job-admin
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "9900:9900"
    volumes:
      # 配置文件
      - /docker/ruoyi-xxl-job-admin/logs/:/ruoyi/xxl-job-admin/logs
    privileged: true
    network_mode: "host"

  ruoyi-gateway:
    image: 43.142.124.79:8060/tyjr/ruoyi-gateway:1.2.0
    container_name: ruoyi-gateway
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "8080:8080"
    volumes:
      # 配置文件
      - /docker/ruoyi-gateway/logs/:/ruoyi/gateway/logs
    privileged: true
    network_mode: "host"

  ruoyi-auth:
    image: 43.142.124.79:8060/tyjr/ruoyi-auth:1.2.0
    container_name: ruoyi-auth
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "9200:9200"
    volumes:
      # 配置文件
      - /docker/ruoyi-auth/logs/:/ruoyi/auth/logs
    privileged: true
    network_mode: "host"

  ruoyi-system:
    image: 43.142.124.79:8060/tyjr/ruoyi-system:1.2.0
    container_name: ruoyi-system
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "9201:9201"
    volumes:
      # 配置文件
      - /docker/ruoyi-system/logs/:/ruoyi/system/logs
    privileged: true
    network_mode: "host"

  ruoyi-gen:
    image: 43.142.124.79:8060/tyjr/ruoyi-gen:1.2.0
    container_name: ruoyi-gen
    environment:
      # 时区上海
      TZ: Asia/Shanghai
      SEATA_IP: 49.234.46.246
    ports:
      - "9202:9202"
    volumes:
      # 配置文件
      - /docker/ruoyi-gen/logs/:/ruoyi/gen/logs
    privileged: true
    network_mode: "host"

  ruoyi-job:
    image: 43.142.124.79:8060/tyjr/ruoyi-job:1.2.0
    container_name: ruoyi-job
    environment:
      # 时区上海
      TZ: Asia/Shanghai
    ports:
      - "9203:9203"
    volumes:
      # 配置文件
      - /docker/ruoyi-job/logs/:/ruoyi/job/logs
    privileged: true
    network_mode: "host"

  ruoyi-resource:
    image: 43.142.124.79:8060/tyjr/ruoyi-resource:1.2.0
    container_name: ruoyi-resource
    environment:
      # 时区上海
      TZ: Asia/Shanghai
      SEATA_IP: 49.234.46.246
      # 注册到注册中心的IP,这里我们选择宿主机的IP
      DUBBO_IP_TO_REGISTRY: 49.234.46.246
      # 注册到注册中心的端口
      DUBBO_PORT_TO_REGISTRY: 20881
      DUBBO_PORT_TO_BIND: 20881
    ports:
      - "9300:9300"
      - "20881:20881"
    volumes:
      # 配置文件
      - /docker/ruoyi-resource/logs/:/ruoyi/resource/logs
    privileged: true
    network_mode: "host"


#################################################################################################
#################################### 以下为扩展根据需求搭建 #########################################
#################################################################################################

  elasticsearch:
    image: elasticsearch:7.17.2
    container_name: elasticsearch
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      # 设置集群名称
      cluster.name: elasticsearch
      # 以单一节点模式启动
      discovery.type: single-node
      ES_JAVA_OPTS: "-Xms512m -Xmx512m"
    volumes:
      - /docker/elk/elasticsearch/plugins:/usr/share/elasticsearch/plugins
      - /docker/elk/elasticsearch/data:/usr/share/elasticsearch/data
      - /docker/elk/elasticsearch/logs:/usr/share/elasticsearch/logs
    network_mode: "host"

  kibana:
    image: kibana:7.17.2
    container_name: kibana
    ports:
      - "5601:5601"
    depends_on:
      # kibana在elasticsearch启动之后再启动
      - elasticsearch
    environment:
      #设置系统语言文中文
      I18N_LOCALE: zh-CN
      # 访问域名
      # SERVER_PUBLICBASEURL: https://kibana.cloud.com
    volumes:
      - /docker/elk/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml
    network_mode: "host"

  logstash:
    image: logstash:7.17.2
    container_name: logstash
    ports:
      - "4560:4560"
    volumes:
      - /docker/elk/logstash/pipeline/logstash.conf:/usr/share/logstash/pipeline/logstash.conf
      - /docker/elk/logstash/config/logstash.yml:/usr/share/logstash/config/logstash.yml
    depends_on:
      - elasticsearch
    network_mode: "host"

  mqnamesrv:
    image: apache/rocketmq:4.9.4
    container_name: mqnamesrv
    ports:
      - "9876:9876"
    environment:
      JAVA_OPT: -server -Xms512m -Xmx512m
    command: sh mqnamesrv
    volumes:
      - /docker/rocketmq/namesrv/logs:/home/rocketmq/logs/rocketmqlogs
    network_mode: "host"

  mqbroker1:
    image: apache/rocketmq:4.9.4
    container_name: mqbroker1
    ports:
      - "10911:10911"
      - "10909:10909"
      - "10912:10912"
    environment:
      JAVA_OPT_EXT: -server -Xms512M -Xmx512M -Xmn256m
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.9.4/conf/broker.conf
    depends_on:
      - mqnamesrv
    volumes:
      - /docker/rocketmq/broker1/conf/broker.conf:/home/rocketmq/rocketmq-4.9.4/conf/broker.conf
      - /docker/rocketmq/broker1/logs:/home/rocketmq/logs/rocketmqlogs
      - /docker/rocketmq/broker1/store:/home/rocketmq/store
    network_mode: "host"

  mqconsole:
    image: styletang/rocketmq-console-ng
    container_name: mqconsole
    ports:
      - "19876:19876"
    environment:
      JAVA_OPTS: -Dserver.port=19876 -Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    depends_on:
      - mqnamesrv
    network_mode: "host"

  rabbitmq:
    image: rabbitmq:3.10.6
    container_name: rabbitmq
    build:
      context: ./rabbitmq
    environment:
      RABBITMQ_DEFAULT_USER: ruoyi
      RABBITMQ_DEFAULT_PASS: ruoyi123
    ports:
      - "15672:15672" # 管理界面端口
      - "5672:5672"   # api 端口
    volumes:
      - /docker/rabbitmq/log:/var/log/rabbitmq
      - /docker/rabbitmq/data:/var/lib/rabbitmq
    network_mode: "host"

  zookeeper:
    image: 'bitnami/zookeeper:3.8.0'
    container_name: zookeeper
    ports:
      - "2181:2181"
    environment:
      TZ: Asia/Shanghai
      ALLOW_ANONYMOUS_LOGIN: "yes"
      ZOO_SERVER_ID: 1
      ZOO_PORT_NUMBER: 2181
    network_mode: "host"

  kafka:
    image: 'bitnami/kafka:3.2.0'
    container_name: kafka
    ports:
      - "9092:9092"
    environment:
      TZ: Asia/Shanghai
      # 更多变量 查看文档 https://github.com/bitnami/bitnami-docker-kafka/blob/master/README.md
      KAFKA_BROKER_ID: 1
      # 监听端口
      KAFKA_CFG_LISTENERS: PLAINTEXT://:9092
      # 实际访问ip 本地用 127 内网用 192 外网用 外网ip
      KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://192.168.31.165:9092
      KAFKA_CFG_ZOOKEEPER_CONNECT: 127.0.0.1:2181
      ALLOW_PLAINTEXT_LISTENER: "yes"
    volumes:
      - /docker/kafka/data:/bitnami/kafka/data
    depends_on:
      - zookeeper
    network_mode: "host"

  kafka-manager:
    image: sheepkiller/kafka-manager:latest
    container_name: kafka-manager
    ports:
      - "19092:19092"
    environment:
      ZK_HOSTS: 127.0.0.1:2181
      APPLICATION_SECRET: letmein
      KAFKA_MANAGER_USERNAME: ruoyi
      KAFKA_MANAGER_PASSWORD: ruoyi123
      KM_ARGS: -Dhttp.port=19092
    depends_on:
      - kafka
    network_mode: "host"

6.JenkinsFile 编写

1.使用JenkinsFile 生成地址
http://43.142.124.79:8888/job/QT-Cloud-Server/pipeline-syntax/
根据若依-plus的情况,将微服务分成三组 构建三个Jenkins 流水线服务
![image.png](https://img-blog.csdnimg.cn/img_convert/89800b0981c73055645a47a09b906157.png#clientId=u89a456ae-8013-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=222&id=u1511a9eb&margin=[object Object]&name=image.png&originHeight=278&originWidth=1552&originalType=binary&ratio=1&rotation=0&showTitle=false&size=51284&status=done&style=none&taskId=u0ed1e4d4-a8bf-43f1-91aa-b8d12743295&title=&width=1241.6)
Jenkinsfile_Pulic 公共模块

//git 凭证id
def git_auth="0dbfe1d3-6f31-4040-b020-261362eea907"
//git 地址
def git_url="https://gitee.com/quantongsui/QT-Cloud-Server.git"
//版本号
def tag="1.2.0"
// harbor_url
def harbor_url ="43.142.124.79:8060"
//镜像库名称
def harbor_project="tyjr"
//镜像库账号密码
def harbor_auth="281ac9d6-ec25-48c7-8d81-6e60e7d0e5ee"
//def harbor_username="suiquantong"
//def harbor_password="Suiqt@123"

node {

        //把选择的项目信息转为数组
    def selectedProjects = "${project_name}".split(',')

    stage("拉取代码"){
        echo "拉取代码"
        checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
    stage("代码审查"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "代码审查"
          //删除 空的镜像
          //sh "docker images|grep none|awk '{print \$3}'|xargs docker rmi -f"
    }
    stage("编译安装公共子工程"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "编译安装公共子工程"
          //bom
          sh "mvn -f ruoyi-common/ruoyi-common-alibaba-bom  clean install"
          sh "mvn -f ruoyi-common/ruoyi-common-bom  clean install"
          sh "mvn -f ruoyi-api/ruoyi-api-bom  clean install"
          sh "mvn -f ruoyi-api/ruoyi-api-system  clean install"
          // 1.common 2.api  注意先后顺序api
          sh "mvn clean install -pl  ruoyi-common,ruoyi-api -am"
          //如果升到1.3或者更高 第一次需要打包的时候 可能需要 全部install  这样公共模块的包才能保存到maven 私服仓库中
//        sh "mvn clean install -D maven.test.skip=true -P prod"
    }
    stage("打包构建微服务,上传镜像"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "打包构建微服务"
          for(int i=0;i<selectedProjects.size();i++){
             //取出每个项目的名称和端口
             def currentProject = selectedProjects[i];
             //项目名称
             def currentProjectName = currentProject.split('@')[0]
             //定义镜像名称
             def imageName = "${currentProjectName}:${tag}"

             sh "mvn -f ${currentProjectName} package -D maven.test.skip=true -P prod  docker:build"
             echo "打标签:${imageName}"
             sh "docker tag ruoyi/${imageName} ${harbor_url}/${harbor_project}/${imageName}"

             withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
                //登录harbor
                sh "docker login -u ${username} -p ${password} ${harbor_url}"
                 //上传
                sh "docker push ${harbor_url}/${harbor_project}/${imageName}"

                echo "推送镜像:${imageName} 成功"

                //删除本地镜像
                sh "docker rmi -f royi/${imageName}"
                sh "docker rmi -f ${harbor_url}/${harbor_project}/${imageName}"
             }
            //部署
            sshPublisher(publishers: [sshPublisherDesc(configName: '43.142.177.41', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/data/shell/deploy.sh $harbor_url $harbor_project $currentProjectName $tag", execTimeout: 990000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
            echo "${currentProjectName}部署成功"

          }

    }

}

Jenkinsfile_Modules 业务模块

//git 凭证id
def git_auth="0dbfe1d3-6f31-4040-b020-261362eea907"
//git 地址
def git_url="https://gitee.com/quantongsui/QT-Cloud-Server.git"
//版本号
def tag="1.2.0"
// harbor_url
def harbor_url ="43.142.124.79:8060"
//镜像库名称
def harbor_project="tyjr"
//镜像库账号密码
def harbor_auth="281ac9d6-ec25-48c7-8d81-6e60e7d0e5ee"
//def harbor_username="suiquantong"
//def harbor_password="Suiqt@123"

node {

        //把选择的项目信息转为数组
    def selectedProjects = "${project_name}".split(',')

    stage("拉取代码"){
        echo "拉取代码"
        checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
    stage("代码审查"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "代码审查"
          //删除 空的镜像
          //sh "docker images|grep none|awk '{print \$3}'|xargs docker rmi -f"
    }
    stage("编译安装公共子工程"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "编译安装公共子工程"
          //bom
          sh "mvn -f ruoyi-common/ruoyi-common-alibaba-bom  clean install"
          sh "mvn -f ruoyi-common/ruoyi-common-bom  clean install"
          sh "mvn -f ruoyi-api/ruoyi-api-bom  clean install"
          // 1.common 2.api  注意先后顺序api
          sh "mvn clean install -pl  ruoyi-common,ruoyi-api -am"
         //如果升到1.3或者更高 第一次需要打包的时候 可能需要 全部install  这样公共模块的包才能保存到maven 私服仓库中
         //sh "mvn clean install -D maven.test.skip=true -P prod"
    }
    stage("打包构建微服务,上传镜像"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "打包构建微服务"
          for(int i=0;i<selectedProjects.size();i++){
             //取出每个项目的名称和端口
             def currentProject = selectedProjects[i];
             //项目名称
             def currentProjectName = currentProject.split('@')[0]
             //定义镜像名称
             def imageName = "${currentProjectName}:${tag}"

             sh "mvn -f ruoyi-modules/${currentProjectName} package -D maven.test.skip=true -P prod  docker:build"
             echo "打标签:${imageName}"
             sh "docker tag ruoyi/${imageName} ${harbor_url}/${harbor_project}/${imageName}"

             withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
                //登录harbor
                sh "docker login -u ${username} -p ${password} ${harbor_url}"
                 //上传
                sh "docker push ${harbor_url}/${harbor_project}/${imageName}"

                echo "推送镜像:${imageName} 成功"

                //删除本地镜像
                sh "docker rmi -f royi/${imageName}"
                sh "docker rmi -f ${harbor_url}/${harbor_project}/${imageName}"
             }
             sshPublisher(publishers: [sshPublisherDesc(configName: '49.234.46.246', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/data/shell/deploy.sh $harbor_url $harbor_project $currentProjectName $tag", execTimeout: 990000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '/')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
             echo "${currentProjectName}部署成功"
          }

    }
//    stage("部署服务"){
//        sshPublisher(publishers: [sshPublisherDesc(configName: '43.142.177.41', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/data/shell/deploy.sh $harbor_url $harbor_project $project_name $tag", execTimeout: 990000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
//
//    }
}

Jenkinsfile_Visual 组件功能模块

//git 凭证id
def git_auth="0dbfe1d3-6f31-4040-b020-261362eea907"
//git 地址
def git_url="https://gitee.com/quantongsui/QT-Cloud-Server.git"
//版本号
def tag="1.2.0"
// harbor_url
def harbor_url ="43.142.124.79:8060"
//镜像库名称
def harbor_project="tyjr"
//镜像库账号密码
def harbor_auth="281ac9d6-ec25-48c7-8d81-6e60e7d0e5ee"
//def harbor_username="suiquantong"
//def harbor_password="Suiqt@123"

node {

        //把选择的项目信息转为数组
    def selectedProjects = "${project_name}".split(',')

    stage("拉取代码"){
        echo "拉取代码"
        checkout([$class: 'GitSCM', branches: [[name: "*/${branch}"]], extensions: [], userRemoteConfigs: [[credentialsId: "${git_auth}", url: "${git_url}"]]])
    }
    stage("代码审查"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "代码审查"
          //删除 空的镜像
          //sh "docker images|grep none|awk '{print \$3}'|xargs docker rmi -f"
    }
    stage("编译安装公共子工程"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "编译安装公共子工程"
          //bom
          sh "mvn -f ruoyi-common/ruoyi-common-alibaba-bom  clean install"
          sh "mvn -f ruoyi-common/ruoyi-common-bom  clean install"
          sh "mvn -f ruoyi-api/ruoyi-api-bom  clean install"
          // 1.common 2.api  注意先后顺序api
          sh "mvn clean install -pl  ruoyi-common,ruoyi-api -am"
         //如果升到1.3或者更高 第一次需要打包的时候 可能需要 全部install  这样公共模块的包才能保存到maven 私服仓库中
         //sh "mvn clean install -D maven.test.skip=true -P prod"
    }
    stage("打包构建微服务,上传镜像"){
          //定义jenkins 插件中的插件 类似于maven的配置方式 需要公共工具的地址
          echo "打包构建微服务"
          for(int i=0;i<selectedProjects.size();i++){
             //取出每个项目的名称和端口
             def currentProject = selectedProjects[i];
             //项目名称
             def currentProjectName = currentProject.split('@')[0]
             //定义镜像名称
             def imageName = "${currentProjectName}:${tag}"

             sh "mvn -f ruoyi-visual/${currentProjectName} package -D maven.test.skip=true -P prod  docker:build"
             echo "打标签:${imageName}"
             sh "docker tag ruoyi/${imageName} ${harbor_url}/${harbor_project}/${imageName}"

             withCredentials([usernamePassword(credentialsId: "${harbor_auth}", passwordVariable: 'password', usernameVariable: 'username')]) {
                //登录harbor
                sh "docker login -u ${username} -p ${password} ${harbor_url}"
                 //上传
                sh "docker push ${harbor_url}/${harbor_project}/${imageName}"

                echo "推送镜像:${imageName} 成功"

                //删除本地镜像
                sh "docker rmi -f royi/${imageName}"
                sh "docker rmi -f ${harbor_url}/${harbor_project}/${imageName}"
             }
             sshPublisher(publishers: [sshPublisherDesc(configName: 'nginx', transfers: [sshTransfer(cleanRemote: false, excludes: '', execCommand: "/data/shell/deploy.sh $harbor_url $harbor_project $currentProjectName $tag", execTimeout: 990000, flatten: false, makeEmptyDirs: false, noDefaultExcludes: false, patternSeparator: '[, ]+', remoteDirectory: '', remoteDirectorySDF: false, removePrefix: '', sourceFiles: '/')], usePromotionTimestamp: false, useWorkspaceInPromotion: false, verbose: false)])
             echo "${currentProjectName}部署成功"
          }

    }
}
#! /bin/bash
#接收外部参数
harbor_url=$1
harbor_project=$2
project_name=$3
tag=$4


imageName=$harbor_url/$harbor_project/$project_name:$tag

echo "$imageName"

#查询容器是否存在,存在则删除
containerId=`docker ps -a | grep -w ${project_name}:${tag} | awk '{print $1}'`

if [ "$containerId" !=  "" ] ; then
#停掉容器
docker stop $containerId

#删除容器
docker rm   $containerId

echo "成功删除容器"

fi

#查询镜像是否存在,存在则删除
imageId=`docker images | grep -w $project_name | awk '{print $3}'`

if [ "$imageId" != "" ] ; then
#删除镜像
docker rmi -f $imageId

echo "成功删除镜像"

fi


# 登录Harbor私服
docker login -u suiquantong -p Suiqt@123 $harbor_url
# 下载镜像
docker pull $imageName
# 启动容器

cd   /root/docker/

docker-compose up -d $project_name

echo "容器启动成功"
echo "run backend.sh"
nowtime=$(date "+%Y%m%d%H%M%S")
echo $nowtime
cd /data/frontend
mv dist backup/dist$nowtime

cd /data/frontend
ls

tar -zxvf dist.tar.gz

cp -r dist/* /docker/nginx/html

echo "frontend success"


SonarScanner 代码审核安装配置

![image.png](https://img-blog.csdnimg.cn/img_convert/d67426d70929994572a3cd588bd60154.png#clientId=uab7ddee3-5f1a-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=361&id=ua587af4f&margin=[object Object]&name=image.png&originHeight=451&originWidth=982&originalType=binary&ratio=1&rotation=0&showTitle=false&size=103807&status=done&style=none&taskId=ud01425bf-7b5d-460b-8c2a-3bfcc72b770&title=&width=785.6)![image.png](https://img-blog.csdnimg.cn/img_convert/9a22bfd469e97eedd0d742c7184bb0c1.png#clientId=uab7ddee3-5f1a-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=399&id=udbcbe39e&margin=[object Object]&name=image.png&originHeight=499&originWidth=1008&originalType=binary&ratio=1&rotation=0&showTitle=false&size=140002&status=done&style=none&taskId=ue626ef30-1acb-4e0e-afed-23649f1f39d&title=&width=806.4)![image.png](https://img-blog.csdnimg.cn/img_convert/6e042131dce5473426c215d005bf5c4d.png#clientId=uab7ddee3-5f1a-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=215&id=u93da72bc&margin=[object Object]&name=image.png&originHeight=269&originWidth=612&originalType=binary&ratio=1&rotation=0&showTitle=false&size=81064&status=done&style=none&taskId=ucf34d176-880b-4876-b489-16e9d9aece4&title=&width=489.6)

Shell文件格式错误

sed -i 's/\r//'  depuy.sh

升级时发生的问题记录

每次要运行之前要在本地打一次包,把包放到私有仓库去 ,这样后面相互调用 打包的时候就不会报错

Dubbo 是绑定当前网卡,如果您的几个服务器之前不能互通,服务基本无法正常使用,但是我为了学习Docker 和Jenkins 能确定正常上传镜像 下载镜像 进行部署即可 不需要 确认服务是否正常 所以要注意这个地方,我没试过

附录文档地址:

RuoYi-Cloud-Plus https://gitee.com/JavaLionLi/RuoYi-Cloud-Plus
文档地址:https://gitee.com/JavaLionLi/RuoYi-Cloud-Plus/wikis/pages
整个项目教程 学习文档 参考黑马成需要的 BILIBILI 视频学习 PDF 文件
https://www.bilibili.com/video/BV1kJ411p7mV?share_source=copy_pc
deploy.shfrontend.sh

Logo

更多推荐