在Debian上實現Jenkins自動化,可按以下步驟進行:
sudo apt update
,sudo apt install openjdk-11-jdk
,并驗證安裝:java -version
。wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
,sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ /etc/apt/sources.list.d/jenkins.list'
,然后sudo apt update
。sudo apt install jenkins
,啟動服務并設置開機自啟動:sudo systemctl enable jenkins
,sudo systemctl start jenkins
。pipeline {
agent any
stages {
stage('拉取代碼') {
steps {
git 'https://github.com/your-repo.git'
}
}
stage('運行測試') {
steps {
sh 'python -m pytest tests/'
}
}
stage('構建打包') {
steps {
sh 'python setup.py build'
}
}
stage('部署') {
steps {
sh './deploy.sh'
}
}
}
post {
always {
mail to: 'team@example.com', subject: "構建完成: ${currentBuild.fullDisplayName}", body: "構建 ${currentBuild.fullDisplayName} 已完成。"
}
}
}
若使用UFW防火墻,開放Jenkins端口8080等:sudo ufw allow 8080/tcp
,sudo ufw reload
。