zoukankan      html  css  js  c++  java
  • 9.jenkins+maven+git+springboot 发布

    准备

    1.准备一台装有JDK8的服务器

    2.准备一台装有Jenkins的服务器(JDK+MAVEN) 参见:https://www.cnblogs.com/ff111/p/11868976.html

    3.准备一台有提交代码gitlab服务器 参见:https://www.cnblogs.com/ff111/p/11865464.html

    安装jenkins插件

    Git plugin

    Maven Integration

    publish over SSH

    全局工具配置

    配置JDK

    配置maven

     

     如果有私库需要配置setting.xml文件 详见maven配置(下面是我自己Nexus私服)

    <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <pluginGroups>
      </pluginGroups>
    
      <proxies>
      </proxies>
    
     
      <servers>
          <server>
            <id>releases</id>
            <username>admin</username>
            <password>admin123</password>
          </server>
          <server>
            <id>snapshots</id>
            <username>admin</username>
            <password>admin123</password>
          </server> 
      </servers>
    
      <mirrors>
        <mirror>
          <id>vm</id>
          <mirrorOf>*</mirrorOf>
          <name>vm maven server</name>
          <url> http://192.168.88.84:8081/repository/maven-public/</url>
        </mirror>
         <mirror>
          <id>alimaven</id>
          <name>aliyun maven</name>
          <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
          <mirrorOf>central</mirrorOf>       
         </mirror>
        <mirror>
          <id>nexus-public-snapshots</id>
          <mirrorOf>public-snapshots</mirrorOf> 
          <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>
        </mirror>
      </mirrors>
      <profiles>
        <profile>
            <id>default</id>
                <repositories>
                    <repository>
                        <id>public</id>
                        <url>http://192.168.88.84:8081/repository/maven-public/</url>
                        <releases>
                            <enabled>true</enabled>
                        </releases>
                        <snapshots>
                            <enabled>true</enabled>
                        </snapshots>
                    </repository>
                </repositories>
        </profile>
      </profiles>
    </settings>

     系统配置

    配置远程ssh连接

     

    5.创建一个JOB

     此处注意下A和B 

     这个地方其实就是A,也就是项目的最外层名称

     

     

     

     完整脚本

    #!/bin/bash
    echo "↓↓↓↓↓↓↓↓↓↓执行远程服务器脚本↓↓↓↓↓↓↓↓↓↓"
    echo "输出环境变量"
    export 
    #软连接jdk路径
    ln -s /java/jdk1.8.0_231/bin/java /usr/bin/java
    #app目录
    APP_PATH="/apps/"
    cd ${APP_PATH}
    #获得app名称
    APP_NAME=$(basename $(ls -r *.jar | head -n 1) .jar)
    echo  "获得app名称:${APP_NAME}"
    #获得app进程id,并关闭
    KPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "结束进程ID:${KPID}"
    kill -9 ${KPID}
    echo  "已经停止服务..."
    #删除目录及里面文件
    rm -rf ./${APP_NAME}
    #创建目录
    mkdir ${APP_NAME}
    #剪切应用程序
    mv ${APP_NAME}.jar ./${APP_NAME}
    #进入目录
    cd ${APP_NAME}
    #进行远程执行app,并让重定向日志输出到垃圾站,防止日志文件过大
    nohup java -jar ${APP_NAME}.jar --spring.profiles.active=dev > /dev/null 2>&1 &
    #获得app进程id,验证已运行
    SPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "开始进程ID:${SPID}"
    echo  "应用已经启动..."

    再看下构件时候的日志

    Started by user root
    Running as SYSTEM
    Building in workspace /var/lib/jenkins/workspace/spring-boot-service(中台)
    using credential 358d1100-8096-4ac4-931c-3fb33e360a28
     > git rev-parse --is-inside-work-tree # timeout=10
    Fetching changes from the remote Git repository
     > git config remote.origin.url http://192.168.88.81/root/spring-boot-service.git # timeout=10
    Fetching upstream changes from http://192.168.88.81/root/spring-boot-service.git
     > git --version # timeout=10
    using GIT_ASKPASS to set credentials 
     > git fetch --tags --progress http://192.168.88.81/root/spring-boot-service.git +refs/heads/*:refs/remotes/origin/* # timeout=10
     > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
     > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
    Checking out Revision 3ef66acf950beefcb1f26c369e35c9b5d2d262ed (refs/remotes/origin/master)
     > git config core.sparsecheckout # timeout=10
     > git checkout -f 3ef66acf950beefcb1f26c369e35c9b5d2d262ed # timeout=10
    Commit message: "更新"
     > git rev-list --no-walk 3ef66acf950beefcb1f26c369e35c9b5d2d262ed # timeout=10
    Parsing POMs
    Established TCP socket on 45114
    [spring-boot-api-service] $ /java/jdk1.8.0_231/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-agent-1.13.jar:/maven/apache-maven-3.6.2/boot/plexus-classworlds-2.6.0.jar:/maven/apache-maven-3.6.2/conf/logging jenkins.maven3.agent.Maven35Main /maven/apache-maven-3.6.2 /var/cache/jenkins/war/WEB-INF/lib/remoting-3.33.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven35-interceptor-1.13.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.13.jar 45114
    <===[JENKINS REMOTING CAPACITY]===>channel started
    Executing Maven:  -B -f /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/pom.xml -Dmaven.test.skip=true clean install -U
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Build Order:
    [INFO] 
    [INFO] spring-boot-api                                                    [jar]
    [INFO] spring-boot-project                                                [pom]
    [INFO] spring-boot-service                                                [jar]
    [INFO] 
    [INFO] ----------------------< com.llhu:spring-boot-api >----------------------
    [INFO] Building spring-boot-api 0.1.1                                     [1/3]
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ spring-boot-api ---
    [INFO] Deleting /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ spring-boot-api ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/resources
    [INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ spring-boot-api ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 2 source files to /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ spring-boot-api ---
    [INFO] Not copying test resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ spring-boot-api ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ spring-boot-api ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ spring-boot-api ---
    [INFO] Building jar: /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1.jar
    [INFO] 
    [INFO] --- maven-javadoc-plugin:2.9.1:jar (attach-javadocs) @ spring-boot-api ---
    [INFO] 
    Loading source files for package com.company.project.service...
    Loading source files for package com.company.project.dto.resp...
    Constructing Javadoc information...
    Standard Doclet version 1.8.0_231
    Building tree for all the packages and classes...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/CloudZookeeperFeignService.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/HelloDTO.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/overview-frame.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/package-frame.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/package-summary.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/package-tree.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/package-frame.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/package-summary.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/package-tree.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/constant-values.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/serialized-form.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/class-use/CloudZookeeperFeignService.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/class-use/HelloDTO.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/dto/resp/package-use.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/com/company/project/service/package-use.html...
    Building index for all the packages and classes...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/overview-tree.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/index-all.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/deprecated-list.html...
    Building index for all classes...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/allclasses-frame.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/allclasses-noframe.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/index.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/overview-summary.html...
    Generating /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/apidocs/help-doc.html...
    4 warnings
    [WARNING] Javadoc Warnings
    [WARNING] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/java/com/company/project/service/CloudZookeeperFeignService.java:25: warning - @return tag has no arguments.
    [WARNING] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/java/com/company/project/service/CloudZookeeperFeignService.java:33: warning - @return tag has no arguments.
    [WARNING] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/java/com/company/project/dto/resp/HelloDTO.java:78: warning - @return tag has no arguments.
    [WARNING] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/src/main/java/com/company/project/dto/resp/HelloDTO.java:12: warning - @date is an unknown tag.
    [INFO] Building jar: /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1-javadoc.jar
    [INFO] 
    [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ spring-boot-api ---
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1.jar to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1.jar
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/pom.xml to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1.pom
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1-javadoc.jar to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1-javadoc.jar
    [INFO] 
    [INFO] --------------------< com.llhu:spring-boot-project >--------------------
    [INFO] Building spring-boot-project 1.0                                   [2/3]
    [INFO] --------------------------------[ pom ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ spring-boot-project ---
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.0.6.RELEASE:repackage (default) @ spring-boot-project ---
    [INFO] 
    [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ spring-boot-project ---
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/pom.xml to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-project/1.0/spring-boot-project-1.0.pom
    [INFO] 
    [INFO] --------------------< com.llhu:spring-boot-service >--------------------
    [INFO] Building spring-boot-service 1.0                                   [3/3]
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ spring-boot-service ---
    [INFO] Deleting /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/target
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ spring-boot-service ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 8 resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ spring-boot-service ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 23 source files to /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/target/classes
    [INFO] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/src/main/java/com/conpany/project/configurer/WebMvcConfigurer.java: /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/src/main/java/com/conpany/project/configurer/WebMvcConfigurer.java uses or overrides a deprecated API.
    [INFO] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/src/main/java/com/conpany/project/configurer/WebMvcConfigurer.java: Recompile with -Xlint:deprecation for details.
    [INFO] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/src/main/java/com/conpany/project/configurer/redis/RedisConfig.java: Some input files use unchecked or unsafe operations.
    [INFO] /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/src/main/java/com/conpany/project/configurer/redis/RedisConfig.java: Recompile with -Xlint:unchecked for details.
    [INFO] 
    [INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @ spring-boot-service ---
    [INFO] Not copying test resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ spring-boot-service ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ spring-boot-service ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ spring-boot-service ---
    [INFO] Building jar: /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/target/spring-boot-service.jar
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.0.6.RELEASE:repackage (default) @ spring-boot-service ---
    [INFO] 
    [INFO] --- maven-install-plugin:2.5.2:install (default-install) @ spring-boot-service ---
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/target/spring-boot-service.jar to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-service/1.0/spring-boot-service-1.0.jar
    [INFO] Installing /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/pom.xml to /var/lib/jenkins/.m2/repository/com/llhu/spring-boot-service/1.0/spring-boot-service-1.0.pom
    
    [INFO] ------------------------------------------------------------------------
    [INFO] Reactor Summary:
    [INFO] 
    [INFO] spring-boot-api 0.1.1 .............................. SUCCESS [  3.369 s]
    [INFO] spring-boot-project 1.0 ............................ SUCCESS [  0.356 s]
    [INFO] spring-boot-service 1.0 ............................ SUCCESS [  1.726 s]
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  7.370 s
    [INFO] Finished at: 2021-01-27T21:14:56+08:00
    [INFO] ------------------------------------------------------------------------
    Waiting for Jenkins to finish collecting data
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/pom.xml to com.llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1.pom
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1.jar to com.llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1.jar
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-api/target/spring-boot-api-0.1.1-javadoc.jar to com.llhu/spring-boot-api/0.1.1/spring-boot-api-0.1.1-javadoc.jar
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/pom.xml to com.llhu/spring-boot-service/1.0/spring-boot-service-1.0.pom
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/spring-boot-service/target/spring-boot-service.jar to com.llhu/spring-boot-service/1.0/spring-boot-service-1.0.jar
    [JENKINS] Archiving /var/lib/jenkins/workspace/spring-boot-service(中台)/spring-boot-api-service/pom.xml to com.llhu/spring-boot-project/1.0/spring-boot-project-1.0.pom
    channel stopped
    SSH: Failed to get hostname [ubuntu16jenkins: ubuntu16jenkins: Name or service not known]
    SSH: Connecting with configuration [appServer01] ...
    
    SSH: EXEC: STDOUT/STDERR from command [#!/bin/bash
    echo "↓↓↓↓↓↓↓↓↓↓执行远程服务器脚本↓↓↓↓↓↓↓↓↓↓"
    echo "输出环境变量"
    export 
    #软连接jdk路径
    ln -s /java/jdk1.8.0_231/bin/java /usr/bin/java
    #app目录
    APP_PATH="/apps/"
    cd ${APP_PATH}
    #获得app名称
    APP_NAME=$(basename $(ls -r *.jar | head -n 1) .jar)
    echo  "获得app名称:${APP_NAME}"
    #获得app进程id,并关闭
    KPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "结束进程ID:${KPID}"
    kill -9 ${KPID}
    echo  "已经停止服务..."
    #删除目录及里面文件
    rm -rf ./${APP_NAME}
    #创建目录
    mkdir ${APP_NAME}
    #剪切应用程序
    mv ${APP_NAME}.jar ./${APP_NAME}
    #进入目录
    cd ${APP_NAME}
    #进行远程执行app,并让重定向日志输出到垃圾站,防止日志文件过大
    nohup java -jar ${APP_NAME}.jar --spring.profiles.active=dev > /dev/null 2>&1 &
    #获得app进程id,验证已运行
    SPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "开始进程ID:${SPID}"
    echo  "应用已经启动..."] ...
    ↓↓↓↓↓↓↓↓↓↓执行远程服务器脚本↓↓↓↓↓↓↓↓↓↓
    输出环境变量
    declare -x HOME="/root"
    declare -x LANG="en_US.UTF-8"
    declare -x LANGUAGE="en_US:en"
    declare -x LOGNAME="root"
    declare -x MAIL="/var/mail/root"
    declare -x OLDPWD
    declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
    declare -x PWD="/root"
    declare -x SHELL="/bin/bash"
    declare -x SHLVL="1"
    declare -x SSH_CLIENT="192.168.88.82 51208 22"
    declare -x SSH_CONNECTION="192.168.88.82 51208 192.168.88.61 22"
    declare -x USER="root"
    declare -x XDG_RUNTIME_DIR="/run/user/0"
    declare -x XDG_SESSION_ID="459"
    ln: failed to create symbolic link '/usr/bin/java': File exists
    获得app名称:spring-boot-service
    结束进程ID:
    kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    已经停止服务...
    开始进程ID:72738
    应用已经启动...
    SSH: EXEC: completed after 202 ms
    SSH: Disconnecting configuration [appServer01] ...
    SSH: Transferred 1 file(s)
    SSH: Failed to get hostname [ubuntu16jenkins: ubuntu16jenkins: Name or service not known]
    SSH: Connecting with configuration [appServer02] ...
    
    SSH: EXEC: STDOUT/STDERR from command [#!/bin/bash
    echo "↓↓↓↓↓↓↓↓↓↓执行远程服务器脚本↓↓↓↓↓↓↓↓↓↓"
    echo "输出环境变量"
    export 
    #软连接jdk路径
    ln -s /java/jdk1.8.0_231/bin/java /usr/bin/java
    #app目录
    APP_PATH="/apps/"
    cd ${APP_PATH}
    #获得app名称
    APP_NAME=$(basename $(ls -r *.jar | head -n 1) .jar)
    echo  "获得app名称:${APP_NAME}"
    #获得app进程id,并关闭
    KPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "结束进程ID:${KPID}"
    kill -9 ${KPID}
    echo  "已经停止服务..."
    #删除目录及里面文件
    rm -rf ./${APP_NAME}
    #创建目录
    mkdir ${APP_NAME}
    #剪切应用程序
    mv ${APP_NAME}.jar ./${APP_NAME}
    #进入目录
    cd ${APP_NAME}
    #进行远程执行app,并让重定向日志输出到垃圾站,防止日志文件过大
    nohup java -jar ${APP_NAME}.jar --spring.profiles.active=dev > /dev/null 2>&1 &
    #获得app进程id,验证已运行
    SPID=`(ps -ef | grep ${APP_NAME}.jar | grep -v "grep") | awk '{print $2}'`
    echo  "开始进程ID:${SPID}"
    echo  "应用已经启动..."] ...
    ↓↓↓↓↓↓↓↓↓↓执行远程服务器脚本↓↓↓↓↓↓↓↓↓↓
    输出环境变量
    declare -x HOME="/root"
    declare -x LANG="en_US.UTF-8"
    declare -x LANGUAGE="en_US:en"
    declare -x LOGNAME="root"
    declare -x MAIL="/var/mail/root"
    declare -x OLDPWD
    declare -x PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
    declare -x PWD="/root"
    declare -x SHELL="/bin/bash"
    declare -x SHLVL="1"
    declare -x SSH_CLIENT="192.168.88.82 57460 22"
    declare -x SSH_CONNECTION="192.168.88.82 57460 192.168.88.62 22"
    declare -x USER="root"
    declare -x XDG_RUNTIME_DIR="/run/user/0"
    declare -x XDG_SESSION_ID="37"
    ln: failed to create symbolic link '/usr/bin/java': File exists
    获得app名称:spring-boot-service
    结束进程ID:
    kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
    已经停止服务...
    开始进程ID:4799
    应用已经启动...
    SSH: EXEC: completed after 202 ms
    SSH: Disconnecting configuration [appServer02] ...
    SSH: Transferred 1 file(s)
    Archiving artifacts
    Finished: SUCCESS

    根据自己项目对应上就可以了

    至此,jenkins发布maven springboot程序就发布完了

  • 相关阅读:
    通过包名获取该包下的所有类
    spring各版本下载地址
    Hash函数和消息摘要算法
    @Value在Controller中取值
    Velocity根据模版生成静态html
    所谓人生
    用递归解决问题
    获取客户端IP
    windows下文件名非法字符
    各控件所支持的数据源格式
  • 原文地址:https://www.cnblogs.com/ff111/p/11900597.html
Copyright © 2011-2022 走看看