在 Debian 上搭建 Jenkins 自动化测试环境
一 环境准备与安装
sudo apt update && sudo apt install -y openjdk-11-jdkjava -versioncurl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /devref
sudo apt update && sudo apt install -y jenkins
sudo systemctl enable --now jenkinssudo systemctl status jenkinssudo cat /var/lib/jenkins/secrets/initialAdminPassword二 插件与全局工具配置
sudo jenkins-plugin-cli --plugins gitlab-plugin selenium-plugin htmlpublisher pipeline-plugin三 创建任务与流水线示例
H/5 * * * * 每 5 分钟)或 Webhook(与 GitLab/GitHub 集成)。mvn clean testnpm install && npm test -- --cipip install -r requirements.txt && python -m pytest tests/ --junitxml=results/pytest.xml**/target/*.jar 或 **/dist/*.zip**/results/*.xml)emailext)pipeline {
agent { label 'dism-test-node' }
environment {
LANGS = 'zh-Hans,en,ja,de,fr,es'
GIT_REPO = 'https://gitcode.com/gh_mirrors/di/Dism-Multi-language'
}
stages {
stage('拉取代码') {
steps { git url: env.GIT_REPO, branch: 'main' }
}
stage('依赖安装') {
steps {
sh 'nuget restore Languages.sln'
sh 'pip install -r requirements.txt'
}
}
stage('多语言测试') {
parallel {
stage('UI测试') {
steps {
script {
def langs = env.LANGS.split(',')
langs.each { lang ->
sh "pytest tests/ui_test.py --lang=${lang} --junitxml=results/ui_${lang}.xml"
}
}
}
}
stage('字符串验证') {
steps {
sh 'python scripts/validate_translations.py --input-dir=Languages --output=results/translation_checks.xml'
}
}
}
}
stage('测试报告生成') {
steps {
script {
def allReports = findFiles(glob: 'results/*.xml')
allReports.each { report ->
junit allowEmptyResults: true, testResults: report.path
}
publishHTML(target: [
allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'results/html',
reportFiles: 'index.html',
reportName: '测试报告'
])
}
}
}
}
post {
success {
slackSend channel: '#dism-ci', message: '✅ Dism-Multi-language测试通过'
}
failure {
slackSend channel: '#dism-ci', message: '❌ Dism-Multi-language测试失败'
sh 'curl -d "status=failed" https://api.example.com/notify'
}
}
}
四 触发策略与通知
H/5 * * * *)。五 运行与排错要点
sudo ufw allow 8080/lib/systemd/system/jenkins.service 中的 Environment="JENKINS_PORT=8081",然后 sudo systemctl daemon-reload && sudo systemctl restart jenkinsls results/ 调试。.hpi 插件包。