Jenkins is an open source continuous integration (CI) tool that provides a friendly operation interface. It is mainly used for continuous and automatic construction/testing of software projects and monitoring the operation of external tasks. Written in the Java language, Jenkins can run in popular servlet containers like Tomcat or stand alone. Usually used in conjunction with version management tools (SCM), build tools. Commonly used version control tools include SVN, GIT, and build tools include Maven, Ant, and Gradle
1 installation
Install using docker on ubuntu
1.1 Environment installation
jdk
Download the corresponding version from the official website Java Downloads | Oracle
Here select x64.tar.gz
Extract it to the usr/local directory in ubuntu
tar -zxvf jdk-8u371-linux-x64.tar.gz -C /usr/local
Configure environment variables
vim /etc/profile
#追加
export JAVA_HOME=/usr/local/jdk1.8.0_371
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export JRE_HOME=$JAVA_HOME/jre
#生效
source /etc/profile
#验证
java -version
maven
Official website to download the corresponding version maven download
select bin.tar.gz
Unzip to usr/local
tar -zxvf maven.tar.gz -C /usr/local
Edit setting.xml
#进入maven->conf目录
#编辑settings.xml
vim settings.xml
#增加mirror
<mirror>
<id>nexus-aliyun</id>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
#编辑jdk1.8 编译插件
#在profiles中增加
<profile>
<id>jdk8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
#在settings中增加
<activeProfiles>
<activeProfile>jdk8</activeProfile>
</activeProfiles>
#环境变量
vim /etc/profile
#追加
export M2_HOME=/usr/local/apache-maven-3.9.3
export PATH=$M2_HOME/bin:$PATH
#生效
source /etc/profile
#验证
mvn -version
Maven home: /usr/local/apache-maven-3.9.3
Java version: 1.8.0_371, vendor: Oracle Corporation, runtime: /usr/local/jdk1.8.0_371/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-113-generic", arch: "amd64", family: "unix"
docker
Need docker and docker compose, see here for installation
1.2 jenkins installation
#拉去镜像
docker pull jenkins/jenkins:2.401.2-lts
#在/usr/local下创建一个docker目录,并创建docekr-jenkins目录
#在该目录下创建一个docker-compose.yaml
version: "3.1"
services:
jenkins:
image: jenkins/jenkins:2.401.2-lts
container_name: jenkins
ports:
- 8080:8080
- 50000:50000
volumes:
- ./data/:/var/jenkins_home/
#docker-compose 构建
#在当前目录下
docker-compose up -d
#需要对当前目录的data目录增加权限
chmod 777 -R data
#重启容器
docker-compose restart
#查看日志
docker logs -f jenkins
#得到密码
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
1717a4d7c81e4459896c886435f67j94
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
#访问服务器ip:8080即可
#如果插件安装太慢或安装失败
可以在数据卷中的hudson.modle.UpdataCenter.xml修改镜像地址
https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json
Visit ip:8080 to enter the jenkins UI page
after entering
Log in with the default administrator account
In the status of admin in the upper left corner, slide down to password, and change the password to 1234Qwer
2 maven jdk docker loading
Since the download of maven and jdk inside jenkins is too slow, it is necessary to load the jdk and maven installed in the environment in 1.1 into jenkins
#将jdk和maven移动到安装jenkins的data目录下
mv /usr/local/jdk /usr/local/docker/docker-jenkins/data
mv /usr/local/maven /usr/local/docker/docker-jenkins/data
Modify docker-compose.yml
version: "3.1"
services:
jenkins:
image: jenkins/jenkins:2.401.2-lts
container_name: jenkins
ports:
- 8080:8080
- 50000:50000
volumes:
- ./data/:/var/jenkins_home/
- /var/run/docker.sock:/var/run/docker.sock
- /usr/bin/docker:/usr/bin/docker
- /etc/docker/daemon.json:/etc/docker/daemon.json
rebuild jenkins
docker-compose up -d
3 Install the plugin
Search and install in System Management->Plugin Management->available plugins, restart Jenkins after the installation is complete, and then enter the UI to configure the plugin installation instructions that need to be configured
gitlab
Connect gitlab tool
gitlab add global credentials
# 进入
系统管理 -> credentials -> stores scoped to jenkins -> system -> 全局凭证 -> add credentials -> user/password
# 使用gitlab用户名密码
gitlab 用户名gitlab用户名,密码gitlab密码
id设置为 gitlab-user-pass
# 保存
Git Parameter
git parameter plugin, used when doing project parameterized build
Config File Provider
Used to load external configuration files, such as Maven's settings.xml or k8s' kubeconfig, etc.
Node and Label parameter
Node label parameter configuration
Build Authorization Token Root
Used to create token credentials
Publish over SSH
remote ssh operation
In System Management -> System Configuration, drop down to Publish over SSH
The name is arbitrary, the address is the server ip to be connected, the user name, the directory sent to the target server, the password of the user name is added in the advanced level, and the mirror test connection