在 CentOS 上“集成 Jenkins + Git”,通常包含三部分工作:
下面给你一套可直接照着做的流程。
sudo yum install -y git
git --version
一般安装路径为
/usr/bin/git
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 jenkins
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
浏览器访问:
http://服务器IP:8080
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
https://github.com/yourname/yourrepo.git
或git@github.com:yourname/yourrepo.git
*/main
pipeline {
agent any
stages {
stage('Clone') {
steps {
git branch: 'main',
url: 'https://github.com/yourname/yourrepo.git',
credentialsId: 'git-cred'
}
}
}
}
Jenkins →
Manage Jenkins → Global Tool Configuration → Git
Name: Default
Path to Git executable: /usr/bin/git
sudo usermod -aG wheel jenkins
sudo chmod 777 /var/lib/jenkins
sudo -u jenkins ssh-keygen -t rsa
sudo -u jenkins cat ~/.ssh/id_rsa.pub
把公钥加到 GitHub / GitLab
如果你告诉我:
我可以给你更精确的配置示例。