Giter Club home page Giter Club logo

ci-cd's Introduction

基于Jenkins+Tomcat实现CI/CD

人员构成

组员

  • 徐家辉
  • 顾一辉
  • 茅悦田
  • 原帅

需要准备的项

  • Java
  • Jenkins
  • Maven
  • Ngrok
  • Tomcat
  • 项目代码(本文以 springboot 项目为例)

搭建CI环境

为了实现本地修改代码push到Github上之后Jenkins能实现自动构建,需要在Github个人页面中完成webhook配置和取得Token以便jenkins访问

  1. 生成Github个人token并妥善保存

    avatar

  2. 进入所需要使用CI/CD环境的仓库下,添加webhook

    avatar avatar

  3. 使用Ngrok将本机端口开放,使Jenkins可以通过webhook实现push后自动构建

    avatar

  4. 开放端口后webhook显示连接成功

    avatar

Jenkins系统管理

  1. 下载Jenkins后用命令行打开,安装推荐插件,创建账号后进入Jenkins使用界面

    avatar avatar

  2. 安装 Github Plugin, Maven Integration Plungin 等插件

  3. 进入系统设置

    avatar

  • Github server配置

    avatar

  • 点击Add,这里的secret就填写github提供的个人token

    avatar avatar

  • 完成系统设置

  1. 进入全局工具配置

    avatar
  • Maven Configuration

    avatar

  • JDK安装

    avatar

  • Git配置

    avatar

  • Maven安装

    avatar

  • 完成全局工具配置

构建项目

  1. 在Jenkins中构建一个maven项目

    avatar

  2. 进入项目配置

    avatar

  3. 使用Git进行源码管理,需提供github仓库URL和Github账号密码

    avatar

  4. 构建触发器,选择此项是为了利用webhook实现push后自动构建

    avatar

  5. 构建环境,仍使用Token授权

    avatar

  6. Build

    avatar

  7. 构建后操作

    avatar

  • 配置完成(^_^)

搭建CD环境

maven 项目需要将打包方式设置为 .war 以进行后续部署。

  1. 项目结构一览

    project structure

  2. 修改pom.xml

  • 设置 .war 打包方式

      <packaging>war</packaging>
    

    war

  • 添加 tomcat 依赖

      <dependencies>
    
              ...   <!-- other dependencies -->
    
              <dependency>
                      <groupId>org.springframework.boot</groupId>
                      <artifactId>spring-boot-starter-tomcat</artifactId>
                      <scope>provided</scope>
              </dependency>
      </dependencies>
    
  1. 修改启动类

    SpringBootApp

在项目通过CI(jenkins构建和测试)后,需要自动部署到web应用服务器(tomcat)上。

  1. 启动 tomcat

     cd /d D:\apache-tomcat-9.0.7\bin
     startup tomcat
    

    tomcat

  2. jenkins 构建项目后打包成 .war 包,在 build 后执行 Windows batch command

     copy C:\Users\DNZ\\.jenkins\workspace\cicdmaven\target\demo-0.0.1-SNAPSHOT.war D:\apache-tomcat-9.0.7\webapps
    

    jenkins 打包的 war 包部署到本机 tomcat 的 /webapps 目录下

    post

  3. tomcat 检测到 .war 包,进行部署

    tomcat success

  4. 打开浏览器,访问部署在 8080 端口的 demo-0.0.1-SNAPSHOT 项目,成功。

    request

测试效果

  1. 修改项目并push

    avatar

  2. Jenkins开始自动构建

    avatar

  3. 构建成功并通过测试

    avatar avatar

  4. Github hook日志

    avatar

  5. 成功部署,查看修改后页面

    avatar

ci-cd's People

Contributors

dnzlike avatar yssjtu avatar guyihui avatar redsmallpanda avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.