在 CentOS 上“集成 Jenkins + Git”,通常包含三部分:安装 Jenkins、安装 Git、在 Jenkins 中配置 Git 并拉取代码。下面给你一套常用且可落地的步骤(以 CentOS 7/8 为例,Jenkins 2.x)。
sudo yum install -y git
# 或 CentOS 8
sudo dnf install -y git
git --version
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 -y java-11-openjdk-devel
sudo yum install -y jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
默认端口:8080
浏览器访问:
http://<服务器IP>:8080
查看初始密码:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
按提示:
Jenkins → Manage Jenkins → Global Tool Configuration
Default/usr/bin/git可用
which git查看路径
Manage Jenkins → Manage Plugins
Git plugin填写:
Repository URL:
https://github.com/xxx/xxx.git
# 或 SSH: git@github.com:xxx/xxx.git
Credentials:
添加 Git 用户名/密码 或 SSH Key
sudo -u jenkins ssh-keygen -t rsa -C "jenkins"
cat /var/lib/jenkins/.ssh/id_rsa.pub
复制到:
Credentials → System → Global credentials
git/var/lib/jenkins/.ssh/id_rsa在 Job 中:
git log -1
pwd
ls
构建后查看控制台输出,能看到 commit 信息即成功。
git: command not foundwhich git
并在 Jenkins Git 配置中写绝对路径
sudo chown -R jenkins:jenkins /var/lib/jenkins/.ssh
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
如果你是指:
可以告诉我你的具体使用场景,我可以给你更针对性的配置示例。