一、Jenkins服务器的部署配置
Jenkins服务器的部署配置工作的一般是由公司的运维人员完成,研发人员只需要了解如何在Jenkins管理界面配置好自己所需自动化构建的项目即可。
二、项目配置
项目配置就跟着步骤一步步配即可,配置完后也可以修改。
重点需要配置的就两个点:
1、源码的GIT地址、认证方式、分支
2、MAVEN的打包命令
3、配置编译完成后的部署脚本(需要自己编写sh脚本)
三、自动化构建原理
Started by timer
Building in workspace /root/.jenkins/workspace/guide-admin
> git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url [email protected]:pay-channel/guide.git # timeout=10
Fetching upstream changes from [email protected]:pay-channel/guide.git
> git --version # timeout=10
> git fetch --tags --progress [email protected]:pay-channel/guide.git +refs/heads/*:refs/remotes/origin/*
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 0fa5667fdfda07681b3de7337ed3fc1a480762d6 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 0fa5667fdfda07681b3de7337ed3fc1a480762d6
> git rev-list 0fa5667fdfda07681b3de7337ed3fc1a480762d6 # timeout=10
Parsing POMs
Established TCP socket on 43716
[guide-admin] $ /opt/tomcat/jdk1.8.0_91/bin/java -cp /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-agent-1.8.1.jar:/opt/maven/boot/plexus-classworlds-2.5.2.jar:/opt/maven/conf/logging jenkins.maven3.agent.Maven33Main /opt/maven /root/.jenkins/war/WEB-INF/lib/remoting-3.16.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-interceptor-1.8.1.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.8.1.jar 43716
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven: -B -f /root/.jenkins/workspace/guide-admin/pom.xml -s /opt/maven/repository/settings.xml -gs /opt/maven/conf/settings.xml clean install -Ptest -Dmaven.test.skip=true
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.qudian:guide-common:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.scope' for org.springframework.boot:spring-boot-dependencies:pom must be one of [provided, compile, runtime, test, system] but is 'import'. @ com.qudian:guide-common:[unknown-version], /root/.jenkins/workspace/guide-admin/guide-common/pom.xml, line 96, column 20
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.qudian:guide-dao:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.qudian:guide-common:jar -> version ${project.version} vs 0.0.1-SNAPSHOT @ com.qudian:guide-dao:[unknown-version], /root/.jenkins/workspace/guide-admin/guide-dao/pom.xml, line 52, column 21
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.qudian:guide-server:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.springframework.boot:spring-boot-maven-plugin is missing. @ com.qudian:guide-server:[unknown-version], /root/.jenkins/workspace/guide-admin/guide-server/pom.xml, line 101, column 21
[WARNING] The expression ${parent.version} is deprecated. Please use ${project.parent.version} instead.
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] guide
[INFO] guide-common
[INFO] guide-dao
[INFO] guide-admin
[INFO] guide-api
[INFO] guide-server
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/pom.xml to /opt/maven/repository/com/qudian/guide/0.0.1-SNAPSHOT/guide-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide-common 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide-common ---
[INFO] Deleting /root/.jenkins/workspace/guide-admin/guide-common/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ guide-common ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/guide-admin/guide-common/src/main/resources
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/guide-admin/guide-common/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ guide-common ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 29 source files to /root/.jenkins/workspace/guide-admin/guide-common/target/classes
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/excel/util/ExcelExportUtil.java:[22,40] sun.net.www.protocol.http.HttpURLConnection is internal proprietary API and may be removed in a future release
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/excel/util/ExcelExportUtil.java:[22,40] sun.net.www.protocol.http.HttpURLConnection is internal proprietary API and may be removed in a future release
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/excel/util/ExcelExportUtil.java:[22,40] sun.net.www.protocol.http.HttpURLConnection is internal proprietary API and may be removed in a future release
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/excel/util/ExcelExportUtil.java:[22,40] sun.net.www.protocol.http.HttpURLConnection is internal proprietary API and may be removed in a future release
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/util/GuavaCacheUtils.java: Some input files use unchecked or unsafe operations.
[WARNING] /root/.jenkins/workspace/guide-admin/guide-common/src/main/java/com/qudian/common/util/GuavaCacheUtils.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ guide-common ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ guide-common ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ guide-common ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ guide-common ---
[INFO] Building jar: /root/.jenkins/workspace/guide-admin/guide-common/target/guide-common-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide-common ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-common/target/guide-common-0.0.1-SNAPSHOT.jar to /opt/maven/repository/com/qudian/guide-common/0.0.1-SNAPSHOT/guide-common-0.0.1-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-common/pom.xml to /opt/maven/repository/com/qudian/guide-common/0.0.1-SNAPSHOT/guide-common-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide-dao 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide-dao ---
[INFO] Deleting /root/.jenkins/workspace/guide-admin/guide-dao/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ guide-dao ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 12 resources
[INFO] Copying 11 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ guide-dao ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 28 source files to /root/.jenkins/workspace/guide-admin/guide-dao/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ guide-dao ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ guide-dao ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ guide-dao ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ guide-dao ---
[INFO] Building jar: /root/.jenkins/workspace/guide-admin/guide-dao/target/guide-dao-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide-dao ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-dao/target/guide-dao-0.0.1-SNAPSHOT.jar to /opt/maven/repository/com/qudian/guide-dao/0.0.1-SNAPSHOT/guide-dao-0.0.1-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-dao/pom.xml to /opt/maven/repository/com/qudian/guide-dao/0.0.1-SNAPSHOT/guide-dao-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide-admin 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide-admin ---
[INFO] Deleting /root/.jenkins/workspace/guide-admin/guide-admin/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ guide-admin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 961 resources
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ guide-admin ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 37 source files to /root/.jenkins/workspace/guide-admin/guide-admin/target/classes
[WARNING] /root/.jenkins/workspace/guide-admin/guide-admin/src/main/java/com/qudian/admin/config/FilterConfig.java: Some input files use unchecked or unsafe operations.
[WARNING] /root/.jenkins/workspace/guide-admin/guide-admin/src/main/java/com/qudian/admin/config/FilterConfig.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ guide-admin ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ guide-admin ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ guide-admin ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ guide-admin ---
[INFO] Building jar: /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.0.0:single (make-assembly) @ guide-admin ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[INFO] Building tar: /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin-assembly.tar.gz
[INFO] Copying files to /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin-assembly
[WARNING] Assembly file: /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin-assembly is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide-admin ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin.jar to /opt/maven/repository/com/qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-admin/pom.xml to /opt/maven/repository/com/qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT.pom
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin-assembly.tar.gz to /opt/maven/repository/com/qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT-assembly.tar.gz
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide-api 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide-api ---
[INFO] Deleting /root/.jenkins/workspace/guide-admin/guide-api/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ guide-api ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/guide-admin/guide-api/src/main/resources
[INFO] skip non existing resourceDirectory /root/.jenkins/workspace/guide-admin/guide-api/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ guide-api ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 7 source files to /root/.jenkins/workspace/guide-admin/guide-api/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ guide-api ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ guide-api ---
[INFO] Not compiling test sources
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ guide-api ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ guide-api ---
[INFO] Building jar: /root/.jenkins/workspace/guide-admin/guide-api/target/guide-api-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide-api ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-api/target/guide-api-0.0.1-SNAPSHOT.jar to /opt/maven/repository/com/qudian/guide-api/0.0.1-SNAPSHOT/guide-api-0.0.1-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-api/pom.xml to /opt/maven/repository/com/qudian/guide-api/0.0.1-SNAPSHOT/guide-api-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building guide-server 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ guide-server ---
[INFO] Deleting /root/.jenkins/workspace/guide-admin/guide-server/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ guide-server ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ guide-server ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 8 source files to /root/.jenkins/workspace/guide-admin/guide-server/target/classes
[INFO] /root/.jenkins/workspace/guide-admin/guide-server/src/main/java/com/qudian/guide/server/facade/impl/GuidePartnerFacadeImpl.java: /root/.jenkins/workspace/guide-admin/guide-server/src/main/java/com/qudian/guide/server/facade/impl/GuidePartnerFacadeImpl.java uses unchecked or unsafe operations.
[INFO] /root/.jenkins/workspace/guide-admin/guide-server/src/main/java/com/qudian/guide/server/facade/impl/GuidePartnerFacadeImpl.java: Recompile with -Xlint:unchecked for details.
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ guide-server ---
[INFO] Not copying test resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ guide-server ---
[INFO] Not compiling test sources
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to /root/.jenkins/workspace/guide-admin/guide-server/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ guide-server ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ guide-server ---
[INFO] Building jar: /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server.jar
[INFO]
[INFO] --- maven-assembly-plugin:3.0.0:single (make-assembly) @ guide-server ---
[INFO] Reading assembly descriptor: src/main/assembly/assembly.xml
[INFO] Building tar: /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server-assembly.tar.gz
[INFO] Copying files to /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server-assembly
[WARNING] Assembly file: /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server-assembly is not a regular file (it may be a directory). It cannot be attached to the project build for installation or deployment.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ guide-server ---
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server.jar to /opt/maven/repository/com/qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT.jar
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-server/pom.xml to /opt/maven/repository/com/qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT.pom
[INFO] Installing /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server-assembly.tar.gz to /opt/maven/repository/com/qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT-assembly.tar.gz
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] guide .............................................. SUCCESS [ 1.103 s]
[INFO] guide-common ....................................... SUCCESS [ 10.034 s]
[INFO] guide-dao .......................................... SUCCESS [ 3.684 s]
[INFO] guide-admin ........................................ SUCCESS [ 31.173 s]
[INFO] guide-api .......................................... SUCCESS [ 1.285 s]
[INFO] guide-server ....................................... SUCCESS [ 13.945 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:06 min
[INFO] Finished at: 2018-12-21T02:28:18+08:00
[INFO] Final Memory: 78M/1180M
[INFO] ------------------------------------------------------------------------
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-api/pom.xml to com.qudian/guide-api/0.0.1-SNAPSHOT/guide-api-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-api/target/guide-api-0.0.1-SNAPSHOT.jar to com.qudian/guide-api/0.0.1-SNAPSHOT/guide-api-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-admin/pom.xml to com.qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin.jar to com.qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-admin/target/guide-admin-assembly.tar.gz to com.qudian/guide-admin/0.0.1-SNAPSHOT/guide-admin-0.0.1-SNAPSHOT-assembly.tar.gz
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-server/pom.xml to com.qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server.jar to com.qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-server/target/guide-server-assembly.tar.gz to com.qudian/guide-server/0.0.1-SNAPSHOT/guide-server-0.0.1-SNAPSHOT-assembly.tar.gz
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/pom.xml to com.qudian/guide/0.0.1-SNAPSHOT/guide-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-dao/pom.xml to com.qudian/guide-dao/0.0.1-SNAPSHOT/guide-dao-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-dao/target/guide-dao-0.0.1-SNAPSHOT.jar to com.qudian/guide-dao/0.0.1-SNAPSHOT/guide-dao-0.0.1-SNAPSHOT.jar
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-common/pom.xml to com.qudian/guide-common/0.0.1-SNAPSHOT/guide-common-0.0.1-SNAPSHOT.pom
[JENKINS] Archiving /root/.jenkins/workspace/guide-admin/guide-common/target/guide-common-0.0.1-SNAPSHOT.jar to com.qudian/guide-common/0.0.1-SNAPSHOT/guide-common-0.0.1-SNAPSHOT.jar
channel stopped
SSH: Connecting from host [java-test]
SSH: Connecting with configuration [jerkins-test-67] ...
SSH: EXEC: STDOUT/STDERR from command [sh /opt/tomcat/tomcat-guide-admin-8001/deploy.sh] ...
979711
kill guide-admin-8001
remove resource files
bin/
bin/stop.sh
bin/start.sh
bin/env.sh
lib/guide-common-0.0.1-SNAPSHOT.jar
lib/mysql-connector-java-5.1.45.jar
lib/druid-1.1.12.jar
lib/fastjson-1.2.44.jar
lib/commons-lang-2.5.jar
lib/commons-lang3-3.1.jar
lib/standard-1.1.2.jar
lib/jstl-1.2.jar
lib/guava-18.0.jar
lib/spring-boot-dependencies-2.0.3.RELEASE.pom
lib/spring-boot-starter-web-2.0.3.RELEASE.jar
lib/spring-boot-starter-2.0.3.RELEASE.jar
lib/spring-boot-2.0.3.RELEASE.jar
lib/spring-core-5.1.1.RELEASE.jar
lib/spring-jcl-5.0.7.RELEASE.jar
lib/spring-context-5.1.1.RELEASE.jar
lib/spring-aop-5.1.1.RELEASE.jar
lib/spring-beans-5.1.1.RELEASE.jar
lib/spring-expression-5.0.7.RELEASE.jar
lib/spring-boot-autoconfigure-2.0.3.RELEASE.jar
lib/spring-boot-starter-logging-2.0.3.RELEASE.jar
lib/logback-classic-1.2.3.jar
lib/logback-core-1.2.3.jar
lib/slf4j-api-1.7.12.jar
lib/log4j-to-slf4j-2.10.0.jar
lib/log4j-api-2.10.0.jar
lib/jul-to-slf4j-1.7.25.jar
lib/javax.annotation-api-1.3.2.jar
lib/snakeyaml-1.19.jar
lib/spring-boot-starter-json-2.0.3.RELEASE.jar
lib/spring-web-5.1.1.RELEASE.jar
lib/jackson-databind-2.9.6.jar
lib/jackson-annotations-2.9.0.jar
lib/jackson-core-2.9.6.jar
lib/jackson-datatype-jdk8-2.9.6.jar
lib/jackson-datatype-jsr310-2.9.6.jar
lib/jackson-module-parameter-names-2.9.6.jar
lib/spring-boot-starter-tomcat-2.0.3.RELEASE.jar
lib/tomcat-embed-core-8.5.31.jar
lib/tomcat-embed-el-8.5.31.jar
lib/tomcat-embed-websocket-8.5.31.jar
lib/hibernate-validator-6.0.10.Final.jar
lib/validation-api-2.0.1.Final.jar
lib/jboss-logging-3.3.2.Final.jar
lib/classmate-1.3.4.jar
lib/spring-webmvc-5.1.1.RELEASE.jar
lib/spring-boot-starter-jdbc-2.1.0.RELEASE.jar
lib/HikariCP-2.7.9.jar
lib/spring-jdbc-5.1.1.RELEASE.jar
lib/spring-tx-5.1.1.RELEASE.jar
lib/spring-boot-starter-thymeleaf-2.0.3.RELEASE.jar
lib/thymeleaf-spring5-3.0.9.RELEASE.jar
lib/thymeleaf-3.0.9.RELEASE.jar
lib/attoparser-2.0.4.RELEASE.jar
lib/unbescape-1.1.5.RELEASE.jar
lib/thymeleaf-extras-java8time-3.0.1.RELEASE.jar
lib/poi-3.17.jar
lib/commons-codec-1.4.jar
lib/commons-collections4-4.1.jar
lib/poi-ooxml-3.17.jar
lib/poi-ooxml-schemas-3.17.jar
lib/xmlbeans-2.6.0.jar
lib/stax-api-1.0.1.jar
lib/curvesapi-1.04.jar
lib/httpclient-4.4.1.jar
lib/httpcore-4.4.1.jar
lib/commons-logging-1.2.jar
lib/commons-io-2.2.jar
lib/lombok-1.16.18.jar
lib/guide-dao-0.0.1-SNAPSHOT.jar
lib/mybatis-spring-1.3.1.jar
lib/mybatis-3.4.5.jar
lib/mapper-3.4.2.jar
lib/persistence-api-1.0.jar
lib/pagehelper-4.2.1.jar
lib/jsqlparser-0.9.5.jar
lib/mybatis-generator-core-1.3.4.jar
lib/spring-boot-starter-cache-2.1.0.RELEASE.jar
lib/spring-context-support-5.1.1.RELEASE.jar
lib/caffeine-2.6.2.jar
lib/spring-boot-configuration-processor-2.0.3.RELEASE.jar
lib/hibernate-jpa-2.0-api-1.0.1.Final.jar
lib/guide-admin-0.0.1-SNAPSHOT.jar
copy resources to /opt/tomcat/tomcat-guide-admin-8001/
cp: cannot stat `start.sh': No such file or directory
start guide-admin-8001
Starting the guide-admin ....OK!
PID: 12236
SSH: EXEC: completed after 2,602 ms
SSH: Disconnecting configuration [jerkins-test-67] ...
SSH: Transferred 1 file(s)
Finished: SUCCESS
这边拷贝一份一次项目构建过程的控制台输出和构建后操作的配置图,可以看出流程是比较清晰的:
1、自动拉取GIT代码
2、根据我们提供的MAVEN命令打包
3、将打包后的文件通过SSH传输至需要部署的服务器
4、根据我们提供的DEPLOY.SH部署项目
解释一下上图的几个参数配置:
SOURCE FILES:需要保留的打包后的文件
REMOVE PREFIX:需要删除的打包后的文件
REMOTE DIRECTORY:SOURCE FILES移动到的位置
EXEC COMMAND:执行自动化部署的脚本
前三个路径都是相对路径:
SOURCE FILES和REMOVE PREFIX的路径实际上是在 /root/.jenkins/workspace 中(由构建控制台输出可以看出)
REMOTE DIRECTORY可以自己在Jenkins管理后台配置服务器的时候配置:这边是配置到 /opt/jenkins。
下面看下DEPLOY.SH脚本到底做了什么:
#!/bin/sh
#defined
GUIDE_HOME="/opt/tomcat/tomcat-guide-admin-8001/"
SOURCE_TARGET="/opt/jenkins/source-target"
ID=`ps -ef | grep java | grep $GUIDE_HOME | awk '{print $2}'`
echo $ID
echo "kill guide-admin-8001"
kill -9 $ID
echo "remove resource files"
cd $GUIDE_HOME
rm -rf bin/ conf/ lib/
tar -zxvf $SOURCE_TARGET/guide-admin/guide-admin-assembly.tar.gz -C $GUIDE_HOME
echo "copy resources to $GUIDE_HOME"
cp start.sh ./bin
cd "$GUIDE_HOME"bin/
echo "start guide-admin-8001"
./start.sh
其实就是:
1、停止原来的项目进程
2、解压ASSEMBLY压缩后的压缩包
3、运行项目启动脚本
这边这些脚本都是抄抄改改,有空的话可以自己学习一下SHELL脚本。
在贴一下启动脚本START.SH
#!/bin/bash
. `dirname $0`/env.sh
cd $DEPLOY_DIR
SERVER_NAME=guide-admin
LOG_DIR="/data/logs/guide-admin"
if [ -z "$SERVER_NAME" ]; then
SERVER_NAME=`hostname`
fi
PIDS=`ps -ef | grep java | grep "SERVER_NAME" |awk '{print $2}'`
if [ -n "$PIDS" ]; then
echo "ERROR: The $SERVER_NAME already started!"
echo "PID: $PIDS"
exit 1
# kill -9 $PIDS
fi
LIB_DIR=$DEPLOY_DIR/lib
LIB_JARS=`ls $LIB_DIR|grep .jar|awk '{print "'$LIB_DIR'/"$0}'|tr "\n" ":"`
#
JAVA_OPTS="-Dlog.dir=$LOG_DIR "
JAVA_OPTS="$JAVA_OPTS -server -Xmx4096m -Xms4096m -Xmn2560m"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintGCDetails -Xloggc:$LOG_DIR/gc.log"
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=$LOG_DIR/"
echo -e "Starting the $SERVER_NAME ...\c"
nohup java $JAVA_OPTS -classpath $LIB_JARS com.qudian.admin.GuideAdminApplication > std.out 2>&1 &
COUNT=0
while [ $COUNT -lt 1 ]; do
echo -e ".\c"
sleep 1
COUNT=`ps -ef | grep java | grep "$DEPLOY_DIR" | awk '{print $2}' | wc -l`
if [ $COUNT -gt 0 ]; then
break
fi
done
echo "OK!"
PIDS=`ps -ef | grep java | grep "$DEPLOY_DIR" | awk '{print $2}'`
echo "PID: $PIDS"
ENV.SH
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
CONF_DIR=$DEPLOY_DIR/conf
export JAVA_HOME=/opt/tomcat/jdk1.8.0_91
export JAVA_BIN=/opt/tomcat/jdk1.8.0_91/bin
export PATH=$JAVA_BIN:$PATH