Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

DescribeThis Shared Library hosts a Custom Step which is an example implementation of the Unit Test step of a MettleCI Pipeline.

Here’s the pseudocode for the Shared Library:

Code Block
languagegroovy
def call(
    def ENVIRONMENTNAME
) {
	try {
        bat label:# 'Upload unit test specs', 
            script: '''
                %AGENTMETTLECMD% remote upload ^
                -host %IISENGINENAME% ^
                -username %MCIUSERNAME% -password %MCIPASSWORD% ^
                -source unittest ^
                -transferPattern "**/*" ^
                -destination %ENGINEUNITTESTBASEDIR%/specs/%DATASTAGE_PROJECT%
            '''

        bat label: 'Configure Properties',# Configure Properties
             script: '''
                %AGENTMETTLECMD% properties config ^
                -baseDir datastage ^
                -filePattern "cleanup_unittest.sh" ^
                -properties var.%ENVID% ^
                -outDir config
            '''

        bat label: '# Create unit test report dir',
             script: "if not exist \"unittest-reports\" mkdir \"unittest-reports\""

        bat label: '# Run Unit Tests',
             script: """
                %AGENTMETTLECMD% unittest test ^
                -domain %IISDOMAINNAME% ^
                -server %IISENGINENAME% ^
                -username %IISUSERNAME% -password %IISPASSWORD% ^
                -project %DATASTAGE_PROJECT% ^
                -specs unittest ^
                -reports unittest-reports ^
                -project-cache \"%AGENTMETTLEHOME%\\cache\\%IISENGINENAME%\\%DATASTAGE_PROJECT%\" ^
                -test-suite \"MettleCI Unit Tests - ${ENVIRONMENTNAME}\"
            """

        bat label: '# Download unit test reports',
        # Publish Unit Test results
script: '''                 %AGENTMETTLECMD% remote download ^
                -host %IISENGINENAME% ^
                -source %ENGINEUNITTESTBASEDIR%/reports ^
                -destination unittest-reports ^
                -transferPattern "%DATASTAGE_PROJECT%/**/*.xml" ^
                -username %MCIUSERNAME% -password %MCIPASSWORD%
            '''

        junit testResults: 'unittest-reports/**/*.xml', 
                allowEmptyResults: true

        bat label: 'Cleanup', 
            script: '''
                %AGENTMETTLECMD% remote execute ^
                -host %IISENGINENAME% ^
                -username %MCIUSERNAME% -password %MCIPASSWORD% ^
                -script "config/cleanup_unittest.sh"
            '''# Cleanup
   }
    catch(e) {
        bat label:# 'Cleanup',
        
    script: '''   throw e     # Propagate error for downstream    %AGENTMETTLECMD% remote execute ^
                -host %IISENGINENAME% ^
                -username %MCIUSERNAME% -password %MCIPASSWORD% ^
                -script "config/cleanup_unittest.sh"
            '''
        throw eerror processing
    }
}