Jenkins 的设置可以分为安装、基础配置、插件、权限、任务、分布式等几部分。下面我按从零开始给你一个常用且实用的 Jenkins 设置流程(以 Linux 为例),如果你用的是 Windows / Docker / K8s,我也可以单独给你说明。
# Ubuntu
sudo apt update
sudo apt install openjdk-11-jdk -y
# CentOS
sudo yum install java-11-openjdk -y
验证:
java -version
Ubuntu
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins -y
CentOS
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install jenkins -y
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins
docker run -d \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
--name jenkins \
jenkins/jenkins:lts
http://服务器IP:8080
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
路径:
Manage Jenkins → Configure System
重点设置:
路径:
Manage Jenkins → Global Tool Configuration
配置:
示例(Git):
Name: Default Git
Path: /usr/bin/git
路径:
Manage Jenkins → Security → Configure Global Security
推荐选择:
New Item → Freestyle project
Repository URL: https://github.com/xxx.git
Credentials: 配置账号密码 / Token
echo "Hello Jenkins"
点击 Build Now
pipeline {
agent any
stages {
stage('拉代码') {
steps {
git 'https://github.com/xxx.git'
}
}
stage('构建') {
steps {
sh 'mvn clean package'
}
}
}
}
Job → Configure → Discard old builds
H 2 * * * # 每天凌晨2点
This project is parameterized
journalctl -u jenkins -f
netstat -tunlp | grep 8080
你可以直接说:
我可以按实战场景一步一步给你配置。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。