Pull the Jenkins image
Find the Jenkins version and pull the Jenkins image from docker
docker search jenkins
docker pull jenkins/jenkins
Check whether the pull is successful in the docker container image
docker images
My side has been pulled from docker before
Docker to run Jenkins
We directly docker run and mount the data. If you don’t know the root authority and port exposure, you can go to the Docker official website to find out. The following maven and git environment configuration can refer to the following article
docker run -d -uroot -p 9095:8080 -p 50000:50000 --name jenkins -v /home/jenkins_home:/var/jenkins_home -v /usr/local/maven/apache-maven-3.8.5:/usr/local/maven -v /usr/local/git/bin/git:/usr/local/git -v /home/www/lib4univ:/home/www/lib4univ -v /etc/localtime:/etc/localtime jenkins/jenkins
After that, we can directly access Jenkins on port 9095. If you can’t access it, you can check the status of the docker container to see if the container has been started.
Jenkins configuration
The following blog is written in great detail
Running Jenkins in a Docker container for automated deployment - Horsleyli's Blog - CSDN Blog
The configuration of Jenkins and jdk, maven, git are all here
jdk, maven, and git can directly use the path we downloaded and configured at the beginning
I am using the username and password to configure Gitee's warehouse
Automatically deploy shell scripts, here is a simple pull operation, automated deployment can be done using shell scripts here
We use web hooks to pull code from the warehouse
For specific operations, please refer to this
Code Cloud Gitee + Jenkins Configuration Tutorial_gitee api url jenkins_Andy_Li_'s Blog-CSDN Blog
Just configure according to these blogs. The following are the problems encountered:
In the process of automated deployment and construction, the user name and password may be wrong. Let's discuss this issue
Jenkins pulls Gitee and an account password error occurs
In the process of automated deployment and construction, the user name and password may be wrong. The first thought may be that the docker network uses a bridge configuration problem, but after testing, there is no problem.
When we use the Docker container to implement automated deployment using Jenkins, the data in the Docker container is mounted on the actual path data, as we just mounted in the docker run code below to mount /home/www/lib4univ in the Docker container The path is mounted to the real /home/www/lib4univ path
/home/www/lib4univ:/home/www/lib4univ
Therefore, when there is an error in the username and password, we will think of performing git operations directly under the real path, such as performing git config to configure the username, password and email address, but this approach is actually invalid.
git config --list
git config --global user.name "ikkkp"
We need to enter the Jenkins container running in docker first, and enter the /home/www/lib4univ path in the container to configure git. As for the permissions of docker, we can directly use root permissions to operate
docker exec <container-id> cat /etc/passwd | grep jenkins
Enter the container and we are just making changes to the .git file
Many questions can now be answered through chatgpt, which is a powerful tool, including error log analysis, code examples, and specific operations gpt can give you an example.