使用Jenkins部署Springboot应用

上篇文章主要讲了关于持续集成的一些基本概念,这篇文章来写实际的介绍持续集成在我所在的公司的运用,当然目前由于人力问题,对于测试和自动化测试的集成也没有达到,这也是日后需要进一步改进的地方。

首先说下公司目前技术栈主要是Java、.NET为后端,vue为前端,移动端为IOS和Android原生应用的开发,这篇文章主要讲介绍基于Jenkins的Java自动化发布。公司的Java开发主要采用Springboot来进行,Springboot会采用Jar包的方式来运行。公司的环境分为开发环境、预生产环境和生产环境,预生产环境和开发环境上想要实现开发人员自动化部署并提交测试人员进行测试,生产环境基于Docker容器化部署,Docker容器的Jenkins部署和打包将在以后的文章中介绍。这里主要是关于Jar包的自动化部署和备份。

1.配置环境环境的解决

首先必须解决的问题是Springboot中的配置问题,这点可以通过Maven工程的POM文件中Profile的配置来达到。如图下所示:

<profiles>

    <profile>
        <!-- 本地开发环境 -->
        <id>dev</id>
        <properties>
            <profiles.active>dev</profiles.active>
            <buildname>custominfo-api</buildname>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <!-- 本地开发环境 -->
        <id>dev-windows</id>
        <properties>
            <profiles.active>dev-windows</profiles.active>
            <buildname>custominfo-api</buildname>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    </profiles>
    


<build>

    <finalName>${buildname}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        </plugins>
        <resources>

<resource><directory>src/main/resources</directory>

            <!-- 资源根目录排除各环境的配置,防止在生成目录中多余其它目录 -->

<excludes>
<exclude>test/*</exclude>
<exclude>production/*</exclude>
<exclude>dev/*</exclude>
<exclude>ppe/*</exclude>
<exclude>dev-windows/*</exclude>
<exclude>wechat/*</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/${profiles.active}</directory>
</resource>

如上就可以通过mvn package -P<profilename>开编译出不同配置文件Jar包

2.Jenkis的安装

这里说的是在Linux下的安装,

(1)安装java

确保服务器上已经安装了JDK 1.8可以通过,jdk可以通过下载orcale官方的Linux版本的JDK或者直接yum install或者apt-get install openjdk来实现,设置JAVA_HOME等环境变量

(2)安装maven

安装Maven,也非常简单直接从apache官方下载解压设置加入到path中

(3)安装Jenkins

从官方下载war包,用java -jar运行并挂后台就行了

    java -jar jenkins.war --httpListenAddress=0.0.0.0 --httpPort=9090
Running from: /Users/lokiewang/Downloads/Misc/jenkins.war
webroot: $user.home/.jenkins
Aug 01, 2019 12:21:03 AM org.eclipse.jetty.util.log.Log initialized
INFO: Logging initialized @447ms to org.eclipse.jetty.util.log.JavaUtilLog
Aug 01, 2019 12:21:04 AM winstone.Logger logInternal
INFO: Beginning extraction from war file
Aug 01, 2019 12:21:05 AM org.eclipse.jetty.server.handler.ContextHandler setContextPath
WARNING: Empty contextPath
Aug 01, 2019 12:21:05 AM org.eclipse.jetty.server.Server doStart
INFO: jetty-9.4.z-SNAPSHOT; built: 2019-02-15T16:53:49.381Z; git: eb70b240169fcf1abbd86af36482d1c49826fa0b; jvm 1.8.0_171-b11
Aug 01, 2019 12:21:06 AM org.eclipse.jetty.webapp.StandardDescriptorProcessor visitServlet
INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
Aug 01, 2019 12:21:06 AM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
INFO: DefaultSessionIdManager workerName=node0
Aug 01, 2019 12:21:06 AM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
INFO: No SessionScavenger set, using defaults
Aug 01, 2019 12:21:06 AM org.eclipse.jetty.server.session.HouseKeeper startScavenging
INFO: node0 Scavenging every 600000ms
Jenkins home directory: /Users/lokiewang/.jenkins found at: $user.home/.jenkins
Aug 01, 2019 12:21:08 AM org.eclipse.jetty.server.handler.ContextHandler doStart
INFO: Started w.@4b21844c{Jenkins v2.176.2,/,file:///Users/lokiewang/.jenkins/war/,AVAILABLE}{/Users/lokiewang/.jenkins/war}
Aug 01, 2019 12:21:08 AM org.eclipse.jetty.server.AbstractConnector doStart
INFO: Started ServerConnector@21d5c1a0{HTTP/1.1,[http/1.1]}{0.0.0.0:9090}
Aug 01, 2019 12:21:08 AM org.eclipse.jetty.server.Server doStart
INFO: Started @4651ms
Aug 01, 2019 12:21:08 AM winstone.Logger logInternal
INFO: Winstone Servlet Engine v4.0 running: controlPort=disabled
Aug 01, 2019 12:21:09 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization
Aug 01, 2019 12:21:09 AM jenkins.InitReactorRunner$1 onAttained
INFO: Listed all plugins
Aug 01, 2019 12:21:11 AM jenkins.InitReactorRunner$1 onAttained
INFO: Prepared all plugins
Aug 01, 2019 12:21:11 AM jenkins.InitReactorRunner$1 onAttained
INFO: Started all plugins
Aug 01, 2019 12:21:11 AM jenkins.InitReactorRunner$1 onAttained
INFO: Augmented all extensions
Aug 01, 2019 12:21:12 AM jenkins.InitReactorRunner$1 onAttained
INFO: Loaded all jobs
Aug 01, 2019 12:21:12 AM hudson.model.AsyncPeriodicWork$1 run
INFO: Started Download metadata
Aug 01, 2019 12:21:12 AM hudson.util.Retrier start
INFO: Attempt #1 to do the action check updates server
Aug 01, 2019 12:21:13 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@5e0743d5: display name [Root WebApplicationContext]; startup date [Thu Aug 01 00:21:13 CST 2019]; root of context hierarchy
Aug 01, 2019 12:21:13 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@5e0743d5]: org.springframework.beans.factory.support.DefaultListableBeanFactory@5949873c
Aug 01, 2019 12:21:13 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@5949873c: defining beans [authenticationManager]; root of factory hierarchy
Aug 01, 2019 12:21:13 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.StaticWebApplicationContext@30ab898: display name [Root WebApplicationContext]; startup date [Thu Aug 01 00:21:13 CST 2019]; root of context hierarchy
Aug 01, 2019 12:21:13 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.StaticWebApplicationContext@30ab898]: org.springframework.beans.factory.support.DefaultListableBeanFactory@6dc434d1
Aug 01, 2019 12:21:13 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6dc434d1: defining beans [filter,legacy]; root of factory hierarchy
Aug 01, 2019 12:21:13 AM jenkins.install.SetupWizard init
INFO: 

*************************************************************
*************************************************************
*************************************************************

Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:

46d7b22dea1c4208b953480fb83caf11

This may also be found at: /Users/lokiewang/.jenkins/secrets/initialAdminPassword

*************************************************************
*************************************************************
*************************************************************

启动后会进入配置界面
可以看到46d7b22dea1c4208b953480fb83caf11为初始化配置需要的

输入46d7b22dea1c4208b953480fb83caf11
选择适合的插件来安装

因为部署需要选择了git、 nodejs 、Push Over SSH、SSH几个插件安装

Lokie博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论
  • 本博客使用免费开源的 laravel-bjyblog v5.5.1.1 搭建 © 2014-2018 lokie.wang 版权所有 ICP证:沪ICP备18016993号
  • 联系邮箱:kitche1985@hotmail.com