Introduction to Jenkins
Jenkins is an open source continuous integration (DI) tool that is widely used in project development and can provide automatic build, test, deployment and other functions. As the leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.
Official website address: https://www.jenkins.io/
It has the following characteristics:
- Continuous Integration and Continuous Delivery
- easy to install
- easy to configure
- plug-in function
- scalability
- distributed
Jenkins installation
This installation of Jenkins is based on the Docker approach. First pull the Jenkins image.
docker pull jenkinsci/blueocean
# 上面拉取的是最新的镜像,当时最新镜像对应的tag应该是1.25.3,所以你也可以按如下拉取
# docker pull jenkinsci/blueocean:1.25.3
Create a Jenkins working directory and mount the directory in the container to this directory, so that we can synchronize the modification of the file on the host to the container.
mkdir -p /usr/local/jenkins
chmod 777 /usr/local/jenkins
Start the container and map the host and container ports at the same time.
# -d 后台方式启动
# -p 映射端口,宿主机端口:容器内端口
# -v 挂载卷,将容器Jenkins工作目录/var/jenkins_home挂载到宿主机目录/usr/local/jenkins
# -name 给容器起个别名
docker run -d -p 8099:8080 -p 50099:50000 -v /usr/local/jenkins:/var/jenkins_home --name myjenkins jenkinsci/blueocean
Check whether the container starts successfully.
[root@chenpihost local]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
538de1b1b1f5 jenkinsci/blueocean "/sbin/tini -- /usr/…" 18 seconds ago Up 17 seconds 0.0.0.0:8099->8080/tcp, :::8099->8080/tcp, 0.0.0.0:50099->50000/tcp, :::50099->50000/tcp myjenkins
Check the Jenkins container logs.
docker logs myjenkins
Add the Jenkins port to the firewall.
firewall-cmd --zone=public --add-port=8099/tcp --permanent
systemctl restart firewalld
firewall-cmd --zone=public --list-ports
Configuring Mirroring Acceleration
Open the file in the Jenkins working directory of the host machine hudson.model.UpdateCenter.xml
.
vim /usr/local/jenkins/hudson.model.UpdateCenter.xml
The original content is as follows:
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://updates.jenkins.io/update-center.json</url>
</site>
</sites>
The url is changed to the official mirror address of Tsinghua University in China, and the final content is as follows:
<?xml version='1.1' encoding='UTF-8'?>
<sites>
<site>
<id>default</id>
<url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url>
</site>
</sites>
Restart the Jenkins service.
docker stop 容器ID
docker start 容器ID
Of course, you can also configure mirror acceleration in the advanced settings of the plug-in after logging in to Jenkins, as follows:
Login to initialize Jenkins
When accessing in a browser http://jenkins所在主机ip:8099
, it will take some time for the following interface to appear.
After waiting, the following interface appears, and a password needs to be entered.
You can check the host /usr/local/jenkins/secrets/initialAdminPassword
file to get the password.
cat /usr/local/jenkins/secrets/initialAdminPassword
Or enter the container and view /var/jenkins_home/secrets/initialAdminPassword
the file to obtain the password.
# 进入容器
docker exec -it 容器ID /bin/bash
# 查看密码
cat /var/jenkins_home/secrets/initialAdminPassword
After entering the password, the following interface appears. It is recommended to choose the first one, and wait for the plug-in to be installed after selection.
Create a root user and log in.
After successful login, enter the following page.