Jenkins implements basic CI operations

Operation screenshot

Push the code into gitlab

Insert image description here
Insert image description here
Insert image description here
Insert image description here

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here

Jenkins pulls gitlab code

Insert image description here
Insert image description here
Insert image description here
Code pulled by Jenkins within the container
Insert image description here
Insert image description here
Insert image description here

Use maven to build the xml and src in the above code into a jar package

Insert image description here
Insert image description here
Insert image description here

Insert image description here
It takes a long time to build for the first time, and the dependencies need to be downloaded. The following figure shows that the dependencies are downloaded and the build is successful.
Insert image description here
Go back to the Jenkins container and see the generated target directory with the built jar package below.
Insert image description here

Push the built jar package to the server

A plug-in configured by Jenkins is used
Insert image description here
to push the jar package in the target directory to the server.
Insert image description here

Enter the mytest project and click build now.
Insert image description here

In this experiment, the server is the virtual machine where jenkins is installed. Enter the server directory to check whether the jar package is successfully pushed.
Insert image description here

Use docker to run the jar package on the server

If you want to run it with docker, push the above jar package to the server to generate a customized image.
Insert image description here
Create a new dockerfile

Insert image description here
Search for a basic image of java on the Internet.
Insert image description here
Edit the rename of the jar package.
Insert image description here
Edit the dockerfile file to complete the construction of the custom image.
Insert image description here
In order to facilitate the operation and management of the image, create a new docker-compose.yml file.
Insert image description here
Pay attention to port conflicts.
Insert image description here

After the above content is prepared, push all the contents of the entire project to the git
Insert image description here
Insert image description here
push operation
Insert image description here
. Enter the Jenkins project and rebuild the project.
Insert image description here
After the construction is completed, enter the Jenkins container to check that the docker folder in the project has been synchronized.
Insert image description here

Implement docker automatic operation

The above is just to push the written docker file to the server. If you want to realize automatic deployment of docker, you need to enter the project on Jenkins and set the post-build command. Note that the first command is an absolute path.
Insert image description here

Build again.
Insert image description here
Enter the target server and check that docker runs successfully.
Insert image description here

Project runs successfully

Insert image description here
With the iteration and submission of the code, building a new version of the code will generate multiple old docker images named none, which can be deleted
Insert image description here

おすすめ

転載: blog.csdn.net/qq_37907454/article/details/132701301