After working so hard for so long, anyone with any talent should have some signs of success.

preface

This article guides you through deploying a SpringBoot project using Jenkins, while implementing simple continuous integration and continuous deployment using Docker and Git. (Project Address: SSO-Merryyou)

The flow chart is as follows:

  1. pushThe code toGithubThe triggerWebHook. For network reasons, this article is usedgitee)
  2. JenkinsPull code from the repository
  3. mavemBuild the project
  4. Code static analysis
  5. Unit testing
  6. buildThe mirror
  7. pushMirror to mirror warehouse (the mirror warehouse used in this paper is netease mirror warehouse)
  8. Update service

Jenkins installation

Download Jenkins

IO /download/ Download the corresponding Jenkins

Initializing a Password

Local access: http://localhost:8080 Enter the password

Select the plug-in

< span style = “box-sizing: border-box; word-break: inherit! Important; word-break: inherit! Important;

Check the plug-ins related to Pipelines

Wait for the plug-in installation to complete

Configure the user name and password

Global configuration

Configure Git,JDK, and Maven

Security configuration

System Management – Global Security Configuration

  • Check Allow Anonymous Read Access
  • Cancels preventing cross-site request forgery

A new task

New task – “pipeline

The build script

Check trigger remote build (WebHooks trigger address) and fill in the simple Pipeline script

#! groovy pipeline{ agent any stages { stage('test'){ steps { echo "hello world" } } } }Copy the code

The test script

Build immediately

Console output

Gitee integration WebHooks

Add the SSH public key

Configuration WebHooks

Use NATApp to penetrate the Intranet

Modify the script

Modify the Pipeline script

#! Groovy pipeline {agent any definition / / warehouse address environment stages {{REPOSITORY = "https://gitee.com/merryyou/sso-merryyou.git"} Git "${REPOSITORY}"} steps {echo "git:${REPOSITORY}"} Steps {echo "start code check"}} stage(' compile + unit test '){steps {echo "start compile" // change directory Dir ('sso-client1') {// repackage bat 'mvn-dmaven.test. skip=true -u clean install'}}} stage(' build mirror '){steps {echo "start Build image "dir (' sso - client1 ') {/ / build mirror bat 'docker build - t hub.c.163.com/longfeizheng/sso-client1:1.0.' Bat 'docker login -u [email protected] -p password hub.c.163.com' // Push the image to bat 'docker push ' Hub.c.163.com/longfeizheng/sso-client1:1.0 '}}} stage (' start the service ') {steps {echo "start sso - merryyou" bat / / restart the service 'docker-compose up -d --build' } } } }Copy the code

Several basic concepts of Pipeline:

  • Stages: Stages. A Pipeline can be divided into stages, each representing a set of operations. Note that Stage is a logical grouping concept that can span multiple nodes.
  • Node: a Node is a Jenkins Node, either Master or Agent, which is the specific runtime environment for executing Step.
  • Step: Step is the most basic operation unit, ranging from creating a directory to building a Docker image, which is provided by various Jenkins plugins.

More Pipeline syntax reference: Pipeline syntax details

test

Docker-compose up -d starts the service

Visit http://sso-taobao:8083/client1 login

The modification effect is as follows:

More renderings

The code download

  • Github:github.com/longfeizhen…
  • Gitee:gitee.com/merryyou/ss…

Recommend the article

  1. Java creates the blockchain family
  2. Spring Security source code analysis series
  3. Spring Data Jpa series
  4. All about Trees in Data Structures (Java Edition)

🙂🙂🙂 focus on wechat small program Java architect journey Bored on the commute? Still reading novels, news? Don’t know how to improve your skills? Here’s the Java architecture article you need. 1.5W + Java engineers are reading it. What are you waiting for?