将 Polymer 测试构建过程集成到 Jenkins CI/CD 管道中



我想使用 polymer-cli 将我们的聚合物测试构建过程集成到 Jenkins CI/CD 管道中。我想自动执行此步骤以构建我们的 Web 组件测试用例。目前,我正在通过在终端上执行"聚合物测试"来手动执行此操作。我还希望自动化过程提供指示失败测试用例的报告。如果在 CI/CD 管道中实现了这一点,请提供步骤。

对于这种情况,我们使用 Jenkins2 管道进行了以下工作设置:

node{        
....
stage('build'){
testresult = bat returnStatus: true, script: 'polymer test --plugin xunit-reporter -l chrome'
step([$class: 'XUnitBuilder', testTimeMargin: '3000', thresholdMode: 1, thresholds: [[$class: 'FailedThreshold', failureNewThreshold: '5', failureThreshold: '10', unstableNewThreshold: '2', unstableThreshold: '5'], [$class: 'SkippedThreshold', failureNewThreshold: '', failureThreshold: '', unstableNewThreshold: '', unstableThreshold: '']], tools: [[$class: 'XUnitDotNetTestType', deleteOutputFiles: true, failIfNotNew: true, pattern: 'TEST-wct.xml', skipNoTestFiles: false, stopProcessingIfError: true]]])
if (testresult != 0) {
currentBuild.result =  "UNSTABLE"
echo "ALERT: Some Unittests failed, see log above."
}
}
....
}

测试结果由 wct-plugin https://github.com/garcus/wct-xunit-reporter 写入 "/TEST-wct.xml"。 XUnit Builder 步骤是这样配置的,它选取该文件并创建测试结果页面。您可以在 Jenkins Pipeline 语法帮助页面中查找该语法。

参见 如何在 Jenkins 上显示 XUnit 测试输出 和 JUnit 格式的测试输出

最新更新