2017-10-17 80 views
1

詹金斯2.85 管道腳本詹金斯NUnit測試結果分析儀管道語法

我試圖建立測試結果分析,這樣我可以附加到電子郵件的報告。 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]) 
    } 

我怎樣才能讓我的測試,以顯示對試驗結果分析?

此外,我想確保我的代碼阻止它發佈測試結果。我是否需要將發佈添加到「最終」行?

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

回答

0

通過我的最後部分添加以下代碼就開始記錄我的測試結果:

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