• SpringBoot项目 使用Jenkins进行自动化部署 (gitLab管理项目)_


    1.部署服务器创建好对应文件夹和启动脚本

    • 创建文件夹
    mkdir /wdcloud/app/rps/rps-module-category
    
    • 创建启动脚本
    cd  /wdcloud/app/rps/rps-module-category
    vim rps-module-category.sh
    
    #!/bin/bash
    APP_HOME=/wdcloud/app/rps/rps-module-category
    APP_JAR=rps-module-category-*.jar
    APP_PIDS=$(ps ax | grep java | grep $APP_HOME | grep -v grep | awk '{print $1}')
    
    function start(){
    	if [ -z "$APP_PIDS" ]; then
    		echo "start project..."
    		exec java -jar $APP_HOME/$APP_JAR  >/dev/null 2>&1 &
    		echo "start project end..."
    	else
    		echo "warning: the spring boot server is started!!!====="$APP_HOME
    		exit 1
    	fi
    }
    
    function stop(){
    	if [ -z "$APP_PIDS" ]; then
    		echo "No spring boot server to stop"
    	else
    		echo "stop project..."
    		kill -s TERM $APP_PIDS
    		echo "stop project end..."
    	fi
    }
    
    
    function restart(){
        stop
        sleep 3
    	APP_PIDS=$(ps ax | grep java | grep $APP_HOME | grep -v grep | awk '{print $1}')
        start
    }
    
    case "$1" in
        start)  
        start
        ;;
        stop)
        stop
        ;;
        restart)
        restart
        ;;
        *)  
        printf 'Usage: %s {start|stop|restart}
    ' "$prog"
        ;;
    esac
    exit 1
    

    2.Jenkins 创建任务

    输入任务名称 -> 选择流水线

    ok-> 选择丢弃旧的构建

    Pipeline - Script 输入对应脚本

    node('master') {
        def mvnHome = tool 'maven11-free'
        def gitUrl = "http://gitlab.wdcloud.cc:10080/utility/rps/rps.git"
        def appName = "rps-module-category"
        def appPath = "/wdcloud/app/rps/rps-module-category"
        def nodeIp = "192.168.9.14"
        def profile = "test"
        
        stage('rmdir') {
            sh "rm -rf ./*"
        }
        stage('git') {
            git branch: 'master', credentialsId: 'd390694c-d99b-4eae-b7d3-f7b75095d29e', url: "${gitUrl}"
        }
    
        stage('Package') {
            sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore -Dmaven.test.skip=true clean package"
        }
        
        stage('Deployment'){
    
            sh """
                ssh jetty@${nodeIp} "${appPath}/${appName}.sh stop || echo not running"
                ssh jetty@${nodeIp} "rm -rf ${appPath}/${appName}-*.jar"
                
                scp -o StrictHostKeyChecking=no -r rps-modules/${appName}/target/${appName}-*.jar jetty@${nodeIp}:${appPath}/
                
                ssh jetty@${nodeIp} "${appPath}/${appName}.sh start || echo not running"
            """
        }
    }
    

    点击保存 配置完成

    3.Jenkins 构建项目 即可进行自动化部署

  • 相关阅读:
    Django系列6:Model简介,ORM,字段类型,约束
    Django系列4:数据常规操作级联数据
    Django系列5:脑图总结
    Sorted Adjacent Differences
    C
    E. Sleeping Schedule
    D. Ehab the Xorcist
    C. Game with Chips
    D. Walk on Matrixv
    Circle of Monsters
  • 原文地址:https://www.cnblogs.com/zhucww/p/10907724.html
Copyright © 2020-2023  润新知