• jenkins部署springboot多项目


    war包的部署问题不大,这里记录jar包的部署过程:

    1:jar包的体积过大问题

    pom.xml参考以下配置(依赖包会分离到target/lib/,jar包体积由几十M缩小到几k)

    <build>
            <plugins>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>com.ylcloud.admin.AdminWebApplication</mainClass>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>3.1.1</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    
            </plugins>
        </build>

    2:

    对各个项目的分离出来的lib要做一下整合,然后上传到服务器启动类的根目录(要注意的是一般项目架构定了之后lib包基本是没什么改动的,只有个别模块的依赖包会持续更新,后续在jenkins的post step传上去就可以了)

    3:

    结合shell进行自动部署,主要是3个脚本,这里只做一下工作记录:

    第一个是进程结束脚本:

    #!/bin/bash
    echo "Stopping SpringBoot Application for CMP"
    #ls
    pid=`ps -ef | grep $1* | grep -v grep | awk '{print $2}'`
    if [ -n "$pid" ]
    then kill -9 $pid
    else echo "no pid"
    fi
    
    echo "run end"

    第二个是项目监控脚本(保证项目按顺序执行)

    #!/bin/bash
    echo "start script ................"
    
    
    
    file=$1
    
    while [ -f $file ]
    do
        echo "find log ........."
        result=`grep "启动成功" $file`
        if [[ "$result" != "" ]]
        then
            echo "springboot start ........."
            break
        else
            echo "running ......."
            sleep 1s
        fi
    done
    echo "springboot Started..........."

    第三个是项目启动脚本:

    #!/bin/bash
    source /etc/profile
    
    jarversion='-0.0.1-SNAPSHOT.jar'
    basepath='/cjh/yl_cloud/'
    
    runjar(){
    
        sh test.sh $1
    
        nohup java -jar $4 $1$jarversion > $basepath$2 & 2>&1 &
        
        sh tt.sh $basepath$2
    
        echo $3
        
    }
    
    runjar 'ylcloud-customer-service' 'nohup.out' '核心模块启动完成' '-Xms10m -Xmx500m'
    
    echo '项目启动成功'

    转载请注明博客出处:http://www.cnblogs.com/cjh-notes/

  • 相关阅读:
    [C++设计模式]observer 观察者模式
    Codeforces 425A Sereja and Swaps(暴力枚举)
    linux中设置TAB键的宽度
    iOS 常见面试图总结2
    网络爬虫初步:从訪问网页到数据解析
    大数据时代之hadoop(二):hadoop脚本解析
    数据格式,訪问信息以及操作数指示符
    javaScript实现日历控件
    每一个程序猿都须要了解的一个SQL技巧
    OpenGL编程逐步深入(九)插值处理
  • 原文地址:https://www.cnblogs.com/cjh-notes/p/9801391.html
Copyright © 2020-2023  润新知