Jenkins在Linux环境集成工具的通用流程与常见工具示例
在Linux(如Ubuntu/CentOS)上集成工具前,需先完成Jenkins的基础安装与配置:
sudo apt update && sudo apt install -y openjdk-11-jdk
验证安装:java -version(需显示Java版本信息)。wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
echo "deb http://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list
sudo apt update && sudo apt install -y jenkins
sudo systemctl start jenkins && sudo systemctl enable jenkins
http://<服务器IP>:8080,按提示完成初始设置(如输入管理员密码、安装推荐插件)。Jenkins集成工具的核心步骤包括:插件安装→全局工具配置→项目任务配置:
Manage Jenkins → Manage Plugins,通过“可选插件”搜索所需工具插件(如Git、Maven、Docker等),选择“Install without restart”(或离线上传.hpi/.jpi文件安装)。Manage Jenkins → Global Tool Configuration,为工具指定安装路径(或勾选“自动安装”)。例如:
/usr/bin/git);/usr/lib/jvm/java-11-openjdk-amd64);/usr/local/apache-maven-3.8.8)。Freestyle Project或Pipeline任务;mvn clean install、Python的pytest);Manage Plugins搜索“Git”并安装。Global Tool Configuration中填写Git路径(如/usr/bin/git)。https://github.com/user/repo.git);Manage Plugins搜索“Maven”并安装。Global Tool Configuration中填写Maven安装路径(如/usr/local/apache-maven-3.8.8),并设置Maven名称(如“maven-3.8.8”)。clean install);-DskipTests跳过测试)。sudo apt install -y docker.io(Ubuntu)或sudo yum install -y docker(CentOS);Manage Plugins搜索“Docker Pipeline”并安装。Global Tool Configuration中填写Docker安装路径(如/usr/bin/docker)。docker.build("my-image:${env.BUILD_NUMBER}"));Manage Plugins搜索“Selenium”并安装。Manage Jenkins → Manage Nodes and Clouds中配置Selenium Grid节点。python selenium_test.py);Manage Plugins搜索“Allure”并安装。wget https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.20.1/allure-commandline-2.20.1.tgz),解压并配置环境变量:tar -zxvf allure-commandline-2.20.1.tgz
sudo mv allure-2.20.1 /opt/allure
echo 'export PATH=$PATH:/opt/allure/bin' >> ~/.bashrc
source ~/.bashrc
Manage Jenkins → Global Tool Configuration中填写Allure路径(如/opt/allure)。allure-results);PATH),可通过Manage Jenkins → Configure System或项目Environment Variables设置;