Ubuntu 上 Jenkins 多任务并行处理实践
一 并行方式总览
二 Pipeline 并行示例与关键要点
pipeline {
agent any
stages {
stage('并行构建') {
parallel {
stage('构建前端') {
steps { echo 'Building frontend...' }
}
stage('构建后端') {
steps { echo 'Building backend...' }
}
}
}
}
}
pipeline {
agent any
stages {
stage('并行构建与超时防护') {
parallel {
stage('构建前端(30秒超时)') {
options { timeout(time: 30, unit: 'SECONDS') }
steps {
echo 'Building frontend...'
// 示例:sleep 40 会触发超时
// sleep(time: 40, unit: 'SECONDS')
}
}
stage('构建后端(45秒超时)') {
options { timeout(time: 45, unit: 'SECONDS') }
steps { echo 'Building backend...' }
}
}
}
}
}
三 多节点分布式并行
四 Ubuntu 上的部署与性能调优
sudo apt update && sudo apt install openjdk-11-jdksudo apt install jenkins,并启动 sudo systemctl start jenkins && sudo systemctl enable jenkins