要解决"Allure报告中显示Jenkins生成的百分比为NAN%和报告URL为空"的问题,你可以尝试以下代码示例:
stage('Generate Allure Report') {
steps {
sh 'your-build-command' // 执行构建命令
script {
def reportPath = "${env.WORKSPACE}/target/allure-report" // 指定Allure报告的路径
def reportUrl = "your-report-url" // 指定报告的URL
if (fileExists(reportPath)) {
allure([
includeProperties: false,
jdk: '',
properties: [],
reportBuildPolicy: 'ALWAYS',
results: [[path: 'your-results-path' ]] // 指定Allure结果的路径
])
echo "Allure报告生成成功!"
echo "报告URL: ${reportUrl}"
} else {
echo "未生成Allure报告,路径不存在:${reportPath}"
echo "报告URL为空"
}
}
}
}
请注意,上述代码中的your-build-command
应替换为实际的构建命令,your-report-url
应替换为实际的报告URL,your-results-path
应替换为实际的Allure结果路径。
此代码在Jenkins Pipeline中使用,它将执行构建命令并生成Allure报告。如果报告成功生成,将打印出报告URL;如果报告生成失败,将打印出路径不存在和报告URL为空的提示。