简体   繁体   中英

Jenkins NUnit test results analyzer pipeline syntax

Jenkins 2.85 Pipeline Script

I am trying to set up the Test Result Analyzer so that I may attach those reports to an email. A TestResult.xml file is created on running my build.

I tried running the following line in my test stage:

step([$class: 'NUnitPublisher', testResultsPattern: 'build\\TestResult.xml', debug: false, keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])

Example:

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])
    }

How can I get my tests to show on Test Result Analyzer?

Also, I want to be sure that my code is preventing it from publishing the test results. Do I need add the publish to the "finally" line?

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'
} 

通过在我的“最后”部分中添加以下代码,它开始记录我的测试结果:

step([$class: 'NUnitPublisher', testResultsPattern: 'build\\TestResult.xml', debug: false, keepJUnitReports: true, skipJUnitArchiver:false, failIfNoResults: true])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM