创建Jenkins流水线测试任务
创建任务
- 创建流水线。进入Jenkins主页,在左侧树单击“新建任务”。图1 创建pipeline任务1
- 打开新建任务页面,填写任务名称,选择流水线选项,单击“确定”按钮创建任务。图2 创建pipeline任务2
- 进入到新创建的Pipeline任务中,左侧树单击“配置”,打开配置页面。将groovy脚本样例复制到流水线配置的脚本中,最后单击“保存”。图3 创建pipeline任务3
- 单击任务左侧树“立即构建”,执行任务。图4 立即构建lkp-tests
- 查看任务执行状态。图5 查看执行状态
- 单击左侧树对应代码中的报告名称,如图6所示。
- 查看报告内容(以云测工具为例)。图7 lkp-tests报告内容
Jenkins流水线测试代码示例
Jenkins Pipeline中集成Lkp Tests工具,请确保运行的用户拥有root权限。
pipeline {
agent any
options {
timeout(time: 1, unit: 'HOURS')
}
parameters {
string(name: 'GIT_URL', defaultValue: 'https://github.com/ruanjue/wtdbg2.git', description: '--> git url <--')
string(name: 'GIT_BRANCH', defaultValue: 'v2.5', description: '--> code branch <--')
string(name: 'GIT_TARGET_DIR_NAME', defaultValue: 'wtdbg2', description: '--> code branch <--')
}
stages{
stage('Git Code') {
agent {
label 'kunpeng_executor'
}
steps {
echo '====== 获取源码 ======'
checkout scmGit(branches: [[name: "${params.GIT_BRANCH}"]],
browser: github("${params.GIT_URL}"),
extensions: [[$class: 'RelativeTargetDirectory',
relativeTargetDir: "${params.GIT_TARGET_DIR_NAME}"],
cleanBeforeCheckout(deleteUntrackedNestedRepositories: true)],
userRemoteConfigs: [[url: "${params.GIT_URL}"]])
}
}
stage('lkp test') {
agent {
label 'kunpeng_executor'
}
steps {
script{
echo '====== lkp test ======'
sh '''
CURDIR=$(pwd)
cp -rf /root/.local/compatibility_testing/template.html.bak /root/.local/compatibility_testing/template.html
sudo lkp run /root/.local/lkp-tests/programs/compatibility-test/compatibility-test-defaults.yaml
cp -rf /root/.local/compatibility_testing/compatibility_report.html $CURDIR
'''
sh(script: "sudo bash /root/.local/compatibility_testing/report_result.sh", returnStdout:true).trim() // 这个是用于判断lkp 命令后生成的结果是否符合预期,需要根据不同的run脚本生成的结果文件去做不同的结果判断结果
}
}
post {
always {
publishHTML(target: [allowMissing: false,
alwaysLinkToLastBuild: false,
keepAll : true,
reportDir : '.',
reportFiles : 'compatibility_report.html',
reportName : 'compatibility test Report']
)
}
}
}
}
}
父主题: 测试

