在CentOS上搭建持续集成环境可以选择使用Jenkins或GitLab CI/CD。以下是详细的步骤:
安装Jenkins
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
sudo systemctl start jenkins
sudo systemctl enable jenkins
配置Jenkins
/var/lib/jenkins/secrets/initialAdminPassword
文件中。安装必要插件
配置Docker
创建Pipeline项目
pipeline {
agent any
stages {
stage('Build') {
steps {
echo 'Building'
}
}
stage('Test') {
steps {
echo 'Testing'
}
}
stage('Deploy') {
steps {
echo 'Deploying'
}
}
}
}
安装GitLab
sudo yum install -y curl policycoreutils-python openssh-server
sudo systemctl start sshd
sudo systemctl enable sshd
sudo yum install postfix
sudo systemctl start postfix
sudo systemctl enable postfix
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install -y gitlab-ce
/etc/gitlab/gitlab.rb
中的external_url
配置项,设置访问的URL。配置GitLab Runner
sudo curl -L https://github.com/gitlab-org/gitlab-runner/releases/download/v12.2.0/gitlab-runner-linux-amd64.tar.gz | sudo tar xz
sudo mv gitlab-runner /usr/local/bin/gitlab-runner
sudo gitlab-runner register --non-interactive --url http://gitlab.example.com --registration-token your-token
以上步骤涵盖了在CentOS上搭建Jenkins和GitLab CI/CD持续集成环境的基本流程,具体配置可以根据实际需求进行调整和优化。