preface

This article guides you through a Jenkins deployment [SpringBoot project] with simple continuous integration and continuous deployment using Docker and Git. (Project Address: SSO-Merryyou)

The flow chart is as follows:

Push code to Github to trigger WebHook. (For network reasons, gitee was used in this paper) Jenkins pulled the code mavem from the warehouse to build the project code static analysis unit test build image push image to the mirror warehouse (the mirror warehouse used in this paper is netease mirror warehouse) update service Jenkins installation

Download Jenkins

fromjenkins.io/download/Download the corresponding Jenkins

Initializing a Password

Local Access:http://localhost:8080Enter 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

accesshttp://sso-taobao:8083/client1The login

The modification effect is as follows:

More renderings

The code download

Github.com/longfeizhen…



Gitee.com/merryyou/ss…



My.oschina.net/merryyou/bl…