It is a practical attempt to operate under only one virtual machine.
1. CentOS installation under VMWare
Set CentOS bridge mode
reference resources:https://www.cnblogs.com/loven…
2. CentOS software installation
1) Docker installation
yum install -y docker
2) JDK installation
reference resources: https://blog.csdn.net/evan_chen_1/article/details/55097252
3) Maven installation
reference resources: https://blog.csdn.net/mynameissls/article/details/54140176
4) Git installation
yum install git
5) Install Jenkins
reference resources: https://www.cnblogs.com/woshimrf/p/6103366.html
3. Jenkins configuration
Install plug-ins
Locale plugin setting Chinese interface
Setting reference: https://www.cnblogs.com/hanxiaohui/p/8136621.html
Publish over SSH configure SSH login CentOS
Remote automatic deployment using publish over SSH plug-in
reference resources: https://www.cnblogs.com/YatHo/p/6739814.html
This example is configured as follows
Locale plugin
Publish Over SSH
4. Create a job named cicd_ demo
5. Configure cicd_ Demo task
The demonstration project address of this example is:https://github.com/chendishen…
1) Configure general
The GIT project in the figure above is one of my test projects
2) Source code management
3) Build trigger
Poll SCM: regularly check the source code changes (according to the version number of SCM software). If there are updates, check out the latest code, and then perform the build action. My configuration is as follows:
Tick poll SCM, fill in the schedule: ` * * * ` (5 *), and ignore the warning
4) Build environment
Not set
5) Build
Maven version selectionmaven
Goals : clean package
6) Post build operations
At the end of the configuration, find “add post build steps” and select “send build artifacts over SSH”
Configuration Description:
1. Ssh server name is the name of publish over SSH configured above
2. Source files refers to the location of the source file, which includes the job file in Jenkins’s working directory,
(/ var / lib / Jenkins / workspace / cicd_demo is the default path. Cicd_demo is my job name. Maven will create a target directory in this file after compilation. Cicd demo *. Jar is the jar package naming prefix + version number after construction
See POM Artifact ID in XML)
3. Remove prefix delete prefix target
4. Remote directory remote directory, combined with the previous publish over SSH configuration, is the / root / test directory. After these configurations are completed, Jenkins will automatically copy the files to / root / test under host B after successful compilation
5. Exec command, my operation here is to copy the host / root / test file to my own / usr / local / project / cicd_ Demo, then enter this directory and execute my buildfimage SH and run sh
Directories and files in the configuration need to be created in advance
mkdir /usr/local/project/cicd_demo
In / usr / local / project / cicd_ Demo directory
Document description
buildimage. SH is used to build images
Dockerfile is the file required to build the image
run. SH is used to start the container
buildimage. SH create
vi /usr/local/project/cicd_demo/buildimage.sh
buildimage. SH content:
docker build -t cicd_demo:1.0 .
Dockerfile creation
vi /usr/local/project/cicd_demo/Dockerfile
Dockerfile content:
#Version information
#Java: latest is the image of CentOS's official JAVA running environment, more than 600 m, which can be pulled to the host in advance
FROM java:latest
MAINTAINER cds "[email protected]"
#It can actually be configured as a variable
ADD cicd-demo-1.0.jar /usr/local/jar/
RUN mv /usr/local/jar/cicd-demo-1.0.jar /usr/local/jar/app.jar
#Open the internal service port cicd demo project port
EXPOSE 8090
CMD ["java","-jar","/usr/local/jar/app.jar"]
run. SH create
vi /usr/local/project/cicd_demo/run.sh
run. SH content:
docker rm -f cicd_demo
docker run --name="cicd_demo" -p 8090:8090 -d cicd_demo:1.0
6.cicd_ Demo task running
The console output is as follows
The auto build task is now complete
7. Result verification
Enter in the physical browserhttp://192.168.1.104:8090/index