Versions Compared

Key

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

This Jenkins Shared Library hosts a Custom Step which is an example implementation of the Compliance step of a MettleCI Pipeline. It provides parameterised set of steps which…

  • Checks out the specified Compliance repository

  • Invokes the MettleCI compliance test command test your repository's DataStage assets against your Compliance rules

  • Publishes the generated JUnit Compliance results back to your Jenkins Controller.

Here’s the pseudocode for the Shared Library:

Code Block
languagegroovy
def call(
    def COMPLIANCE_REPO_CREDENTIALS,
    def COMPLIANCE_REPO_URL,
    def RULESDIR,
    def TESTSUITENAME,
    def CONTINUEONFAIL
) {
    try {
        // Perform a 'git checkout' of a remote repository which is NOT the repository from which this pipeline code was sourced
        checkout([#  
            $class: 'GitSCM', 
            branches: [[name: 'refs/heads/master']], 
            doGenerateSubmoduleConfigurations: false, 
            extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'compliance2']], 
            submoduleCfg: [], 
            userRemoteConfigs: [[ credentialsId: "${COMPLIANCE_REPO_CREDENTIALS}", url:  "${COMPLIANCE_REPO_URL}" ]]
 Git checkout COMPLIANCE_REPO_URL using COMPLIANCE_REPO_CREDENTIALS

     ])          /*// Executes the 'mettleci compliance test' command to test your repository's DataStage jobs against your Compliance rules.
        // Note that 'mettleci compliance test' is mnot the same as 'mettleci compliance query' - See the documentation for more details. 
       */                    
        bat label: "# Compliance Test - ${TESTSUITENAME}",

        # Publish Unit script: """
                %AGENTMETTLECMD% compliance test ^
                    -assets datastage ^
                    -report \Test results as "compliance_report_${TESTSUITENAME}.xml\" ^
                    -junit -test-suite \"${TESTSUITENAME}\"
^                     ${((CONTINUEONFAIL as boolean) == true)? '-ignore-test-failures':''}  ^
                    -rules compliance2\\${RULESDIR} ^catch(e) {
        # Publish Unit Test          -project-cache \"%AGENTMETTLEHOME%\\cache\\%IISENGINENAME%\\%DATASTAGE_PROJECT%\"
                """

        junit testResults: "results as "compliance_report_${TESTSUITENAME}.xml",

            allowEmptyResults: true,
            skipMarkingBuildUnstable: (CONTINUEONFAIL as boolean)
    }
    catch(e) {throw e       # Propagate error junitfor testResults: "compliance_report_${TESTSUITENAME}.xml", 
            allowEmptyResults: true,
            skipMarkingBuildUnstable: (CONTINUEONFAIL as boolean)

        throw edownstream error handling
    }
}