Jenkins 2.85 流水线脚本
我正在尝试设置测试结果分析器,以便我可以将这些报告附加到电子邮件中。运行我的构建时会创建一个 TestResult.xml 文件。
我尝试在测试阶段运行以下行:
step([$class: 'NUnitPublisher', testResultsPattern: 'build\\TestResult.xml', debug: false, keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])
例子:
stage('Test: Check if IIS webApp ON') {
bat 'C:/"Program Files (x86)"/NUnit.org/nunit-console/nunit3-console.exe screenShots/screenShots/bin/Debug/screenShots.dll'
step([$class: 'NUnitPublisher', testResultsPattern: 'build\\TestResult.xml', debug: false, keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])
}
如何让我的测试显示在测试结果分析器上?
另外,我想确保我的代码阻止它发布测试结果。我需要将发布添加到“finally”行吗?
node { try {
notifyBuild('STARTED')
stage('Checkout') {
checkout([$class: 'SubversionSCM',
additionalCredentials: [],
excludedCommitMessages: '',
excludedRegions: '',
excludedRevprop: '',
excludedUsers: 'buildbot',
filterChangelog: false,
ignoreDirPropChanges: false,
includedRegions: '',
locations: [[credentialsId: 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx',
depthOption: 'infinity',
ignoreExternalsOption: true,
local: '.',
remote: "http://my.svn.repo.com/svn/apps/folder"]],
workspaceUpdater: [$class: 'UpdateUpdater']])
}
/* stage('Build webApp') {
bat 'C:/"Program Files (x86)/Microsoft Visual Studio"/2017/Community/MSBuild/15.0/Bin/MSBuild.exe webApp/webApp.sln /m /p:VisualStudioVersion=15.0' //msbuild
}*/
stage('Build Selenium Tests') {
bat 'C:/"Program Files (x86)/Microsoft Visual Studio"/2017/Community/MSBuild/15.0/Bin/MSBuild.exe screenShots/screenShots.sln /m /p:VisualStudioVersion=15.0' //msbuild
}
stage('Test: Check if IIS webApp ON') {
bat 'C:/"Program Files (x86)"/NUnit.org/nunit-console/nunit3-console.exe screenShots/screenShots/bin/Debug/screenShots.dll'
}
} catch (e) {
// If there was an exception thrown, the build failed
currentBuild.result = "FAILED"
throw e
} finally {
// Success or failure, always send notifications
notifyBuild(currentBuild.result)
}
}
def notifyBuild(String buildStatus = 'STARTED') {
// build status of null means successful
buildStatus = buildStatus ?: 'SUCCESSFUL'
// Default values
def colorName = 'RED'
def colorCode = '#FF0000'
def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
def summary = "${subject} (${env.BUILD_URL})"
// Override default values based on build status
if (buildStatus == 'STARTED') {
color = 'YELLOW'
colorCode = '#FFFF00'
} else if (buildStatus == 'SUCCESSFUL') {
color = 'GREEN'
colorCode = '#00FF00'
} else {
color = 'RED'
colorCode = '#FF0000'
}
// Send notifications
slackSend (color: colorCode, message: summary)
emailext subject: '$DEFAULT_SUBJECT',
body: '$DEFAULT_CONTENT',
recipientProviders: [
[$class: 'CulpritsRecipientProvider'],
[$class: 'DevelopersRecipientProvider'],
[$class: 'RequesterRecipientProvider']
],
replyTo: '$DEFAULT_REPLYTO',
to: '$DEFAULT_RECIPIENTS'
}