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 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:  "${URL using COMPLIANCE_REPO_URL}" ]]CREDENTIALS 

      ])          /*// Executes the 'mettleci compliance test' command to test your repository's DataStage jobs against your Compliance rules.
        // Note that 'mettleci compliance test' is mnotnot the same as 'mettleci compliance query' - See the documentation for more details. 
       */ mettleci compliance test $RULESDIR $TESTSUITENAME

    }
        
        bat label: "Compliance Test - ${TESTSUITENAME}",finally {             script: """                 %AGENTMETTLECMD% compliance test ^                     -assets datastage ^// Whether the above is successfult or not...
        junit testResults    -report \"compliance_report_${TESTSUITENAME}.xml\" ^   // Publish CCMT output as JUnit Test Results
          -junit -test-suite \"${TESTSUITENAME}\" ^ allowEmptyResults: true                     ${((CONTINUEONFAIL as boolean) == true)? '-ignore-test-failures':''}  ^       // Don't fail the build on missing test result files or empty test results
-rules compliance2\\${RULESDIR} ^          skipPublishingChecks: true          -project-cache \"%AGENTMETTLEHOME%\\cache\\%IISENGINENAME%\\%DATASTAGE_PROJECT%\"                 """    // Don't automatically publish test results junit testResults: "compliance_report_${TESTSUITENAME}.xml",to Git
             allowEmptyResults: true,
            skipMarkingBuildUnstable: (CONTINUEONFAIL as boolean)     }     catch(e) {         junit testResults: "compliance_report_${TESTSUITENAME}.xml", 
            allowEmptyResults: true,
            skipMarkingBuildUnstable: (CONTINUEONFAIL as boolean)

        throw e// (Optionally) mark the build as successful,even if there are test failures reported
    }
}

Note that this Custom Step makes used of Jenkins' JUnit plugin.