Limited supportBMC provides limited support for this version of the product. As a result, BMC no longer accepts comments in this space. If you encounter problems with the product version or the space, contact BMC Support.BMC recommends upgrading to the latest version of the product. To see documentation for that version, see BMC AMI DevOps for Db2 13.1.

Sample pipeline scripts for Jenkins


You can use BMC AMI DevOps features in Scripted Pipelines and Declarative Pipelines using other jobs (projects). For more information, see Using-BMC-AMI-DevOps-as-part-of-a-pipeline.

The following figures represent sample pipeline scripts for Jenkins:

Sample pipeline script for Schema Change Migration - Scripted Pipeline

The following figure represents a sample pipeline script for Schema Change Migration - Scripted Pipeline:

    import static com.bmc.db2.bmcclient.BMCClientCN.bmcCN;
    import static com.bmc.db2.bmcclient.BMCClientSM.bmcSM;
node {
        bmcSM.reset("BMC_SCHEMA_IDENTICAL")
        bmcSM.reset("BMC_GENERATE_JCL_ONLY")
        bmcSM.reset("BMC_SKIP_COMPARE")
        bmcSM.reset("BMC_SCHEMA_RC")
        bmcCN.reset("BMC_EXEC_RC")
        println "SM GetRC Initial get ==" + bmcSM.getRC("BMC_SCHEMA_RC")
        println "CN GetRC Initial get ==" + bmcCN.getRC("BMC_EXEC_RC")
       
        // Flag if Compare Step show no changes
        boolean Compare_Equal
        Compare_Equal = bmcSM.get("BMC_SCHEMA_IDENTICAL")                
        // Flag if Compare Plugin set to Generate JCL Only
        boolean Gen_Only
        // Flag if Job should start with CDL Import
        boolean Skip_Compare

        // Flag to skip Stages if JCL was not submitted or Compare was equal
        boolean Skip_Stage = false
       

    stage ('Compare Source Schema definition for deployement') {
        build job: 'Compare',
            parameters:
            [string(name: 'Job_ID', value: "${params.Job_ID}"),
             string(name: 'Client_DDL_Directory_Name', value: "${params.Client_DDL_Directory_Name}"),
             string(name: 'Client_DDL_File_Name', value: "${params.Client_DDL_File_Name}"),
             string(name: 'Output_DIR', value: "${WORKSPACE}")]

        Compare_Equal = bmcSM.get("BMC_SCHEMA_IDENTICAL")
        Gen_Only      = bmcSM.get("BMC_GENERATE_JCL_ONLY")
        Skip_Compare  = bmcSM.get("BMC_SKIP_COMPARE")
        println "SCHEMA_MIG_RC==" + bmcSM.getRC("BMC_SCHEMA_RC")        

        if (Compare_Equal) {
           Skip_Stage = true
        } else if (Gen_Only) {
           Skip_Stage = true
        }

        if (!Skip_Stage) {
                emailext attachmentsPattern: '${Job_ID}_*.txt',
                body: '''Please review the changes requested by the developer related to the schema definition of the application.
See attached Impact Report and CDL files.  

You can generate a Compare report using the CDL generated.
<Insert Command Center url>/index.html?perspective=SchemaManager&cdl=#cdlpds#(${Job_ID})

You can approve or reject implementation of changes  by using this link:
${JOB_URL}/
''',
                subject: '$PROJECT_NAME - Build # $BUILD_NUMBER - Approve Change Request',
                to: '<insert Email Address>'
        } else {
            if (Compare_Equal) {
               println "Compare showed no differences"
            } else if (Gen_Only) {
               println "Compare JCL Generated Only, not submitted"
            }
            println "Email notification skipped"
        }        
    }

    stage('Seek DBA approval for Schema changes'){
        if (!Skip_Stage) {
           input "Submit job to change schema definitions?"
        } else {
           echo "Stage Get Approval Skipped"
        }
    }

    stage ('Implement Schema changes and Build Rollback Job') {    
        if (!Skip_Stage) {
            build job: 'Submit-Gen Rollback',
                parameters:
                [string(name: 'Job_ID', value: "${Job_ID}"),
                 string(name: 'Output_DIR', value: "${WORKSPACE}")]                
            println "EXEC_RC==" + bmcCN.getRC("BMC_EXEC_RC")                 
        } else {        
            echo "Stage Submit Skipped"
            // The statement below allow pipeline to remain green and not have all stages flag as red
        }    
    }    
}

Sample pipeline script for Schema Change Migration - Declarative Pipeline using other jobs (projects)

The following figure represents a sample pipeline script for Schema Change Migration - Declarative Pipeline using other jobs (projects):

import static com.bmc.db2.bmcclient.BMCClientCN.bmcCN;
import static com.bmc.db2.bmcclient.BMCClientSM.bmcSM;
pipeline {
    agent any
    stages {
        stage('Compare Developer DDL definition to target') {
            steps {
                script {
                    bmcSM.reset("BMC_SCHEMA_IDENTICAL")
                    bmcSM.reset("BMC_GENERATE_JCL_ONLY")
                    bmcSM.reset("BMC_SKIP_COMPARE")
                    bmcSM.reset("BMC_SCHEMA_RC")
                    bmcCN.reset("BMC_EXEC_RC")
println "SM GetRC Initial get ==" + bmcSM.getRC("BMC_SCHEMA_RC")
            println "CN GetRC Initial get ==" + bmcCN.getRC("BMC_EXEC_RC")

                    // Flag if Compare Step show no changes
                    boolean Compare_Equal
                    Compare_Equal = bmcSM.get("BMC_SCHEMA_IDENTICAL")                
                    // Flag if Compare Plugin set to Generate JCL Only
                    boolean Gen_Only
                    // Flag if Job should start with CDL Import
                    boolean Skip_Compare

            // Flag to skip Stages if JCL was not submitted or Compare was equal
                    //boolean Skip_Stage = false
            }
        build job: 'DevOps Compare',
            parameters:
            [string(name: 'Job_ID', value: "${params.Job_ID}")]
            script {
                Compare_Equal = bmcSM.get("BMC_SCHEMA_IDENTICAL")
                Gen_Only      = bmcSM.get("BMC_GENERATE_JCL_ONLY")
                Skip_Compare  = bmcSM.get("BMC_SKIP_COMPARE")
                println "SCHEMA_MIG_RC==" + bmcSM.getRC("BMC_SCHEMA_RC")

                if (!Compare_Equal && !Gen_Only) {
                        build job: 'DevOps Download Output',
                        parameters:
                        [string(name: 'Job_ID', value: "${params.Job_ID}"),
                        string(name: 'Output_DIR', value: "${WORKSPACE}")]           
                } else {
                        println "SCHEMA_MIG_RC==" + bmcSM.getRC("BMC_SCHEMA_RC")
println "Compare showed no differences"
                        println "Job Output Download Skipped"
                }
            }      
        }
     }
 stage('Generate Email'){
   steps {
   script {   
if (Compare_Equal) {
println "EMAIL: Compare showed no differences - TESTRC1"
}   
if (!Compare_Equal && !Gen_Only) {
emailext attachmentsPattern: '${Job_ID}_*.txt', body: '''Please review the changed requested by the developer related to the schema definition of the application.
See attached Impact Report and CDL files.  

You can generate a Compare report using the CDL generated.
<Insert CDL pds and member>

<Insert Command Center url>/index.html?perspective=SchemaManager&cdl=#cdlpds#(${Job_ID})

You can approve or reject implementation of changes on Subsystem ${SSID} by using this link:
${BUILD_URL}/console''', subject: '$PROJECT_NAME - Approve Change Request', to: <Insert Email Addess(es)>
}
}       
}
}
        stage('Seek Release Manager approval for Schema changes') {
            steps {
                script {
                    if (!Compare_Equal && !Gen_Only) {
                        input "Submit job to change schema definitions?"
                    } else {
                        echo "Stage Get Approval Skipped"
                    }
                }   
            }
        }
        stage('Implement Schema changes') {
            steps {
                script {
                    if (!Compare_Equal && !Gen_Only) {
                        build job: 'DevOps Submit',
                        parameters:
                        [string(name: 'Job_ID', value: "${params.Job_ID}"),
                        string(name: 'Output_DIR', value: "${WORKSPACE}")]     
println "EXEC_RC==" + bmcCN.getRC("BMC_EXEC_RC")          
                    } else {    
                            echo "Stage Submit Skipped"
                    }  
                }   
            }
        }
        stage('Generate Schema Rollback Job') {
            steps {
                script {
                    if (!Compare_Equal && !Gen_Only) {
                        build job: 'DevOps Generate Rollback',
                        parameters:
                        [string(name: 'Job_ID', value: "${params.Job_ID}")]

                    } else {       
                        echo "Stage Generate Rollback Skipped"
                    }  
                }
            }
        }   
    }
}

Sample pipeline script for Schema Change Migration + Schema Standards - Scripted Pipeline

The following figure represents a sample pipeline script for Schema Change Migration + Schema Standards - Scripted Pipeline:

    import static com.bmc.db2.bmcclient.BMCClientCN.bmcCN;
    import static com.bmc.db2.bmcclient.BMCClientSM.bmcSM;
node {
    bmcSM.reset("BMC_SCHEMA_IDENTICAL")
    bmcSM.reset("BMC_GENERATE_JCL_ONLY")
    bmcSM.reset("BMC_SKIP_COMPARE")
    bmcSM.reset("BMC_SCHEMA_RC")
    bmcCN.reset("BMC_EXEC_RC")
    bmcSM.reset("BMC_SCHEMA_STANDARDS_RC")
   
/* BMC AMI Schema Management */
   try {
 
        stage('Common - Authentication') {
/* BMC AMI DevOps Common - Authentication */
bmcAmiAuthentication comtype: 'ZOSMF', debug: false, dpassrun: '${TSO_PASSWORD}', dpassword: '', dport: '${HOST_PORT}', dserver: '${HOST_IP}', duser: '${TSO_ID}', pwdruntime: true, symdir: '${PLUGIN_FILE}'
 parameters:
                        [string(name:   'HOST_IP',      value: "${params.HOST_IP}"),
                         string(name:   'HOST_PORT',    value: "${params.HOST_PORT}"),
                         string(name:   'TSO_ID',       value: "${params.TSO_ID}"),
 string(name:   'PLUGIN_FILE',  value: "${params.PLUGIN_FILE}"),
 password(name: 'TSO_PASSWORD', value: "${params.TSO_PASSWORD}")
                        ]
}
stage('Compare DDL file to Subsystem') {
/* BMC AMI Schema Management */
bmcAmiDb2SchemaChangeMigration acceptableRC: '0004', addCommentCompare: false, addCommentWorkId: false, analysisin: '''//*Analysis Input
//ANALYSIS.ALURPT DD DISP=SHR,
// DSN=&IMPRPT
//ANALYSIS.ALUIN DD *
  SSID  ${SSID}
  WORKID  ${Work ID Owner}.${Work ID Name}
  INCLUDE (DATA AMS SQL )''', cdlRollCheck: false, cdlRollPds: '', cdlpds: '#cdlpds#(${JOB_ID})', cmpbl1: '', cmpbl2: '', cmpbp1: '', cmpbp2: '', cmpddl1: '', cmpddl2: '${DDL_DSN}', compareCommentText: '', compin: '''//*Compare Input
//COMPARE1 EXEC AMAPROCC,
// COND=(1,LT)
//COMPARE.CDL001 DD DISP=SHR,
// DSN=&CDLFILE
//COMPARE.CMPIN2 DD DISP=SHR,
//  DSN=&DDLFILE
//COMPARE.ALUIN DD *
     SSID  ${SSID}
     CMPTYPE1 LOCAL
     CMPTYPE2 DDL
     SCOPETYPE DDL
     NODEFINE''', crule: '', crule1: '', crule2: '', cruleAfter: '', cruleBefore: '', debug: false, disablebuildstep: false, execjclpds: '#execpds#(${JOB_ID})', genjcl: false, impin: '''//*Import Input
//IMPORT.ALUIN DD *
  SSID ${SSID}
  REPLACEWORKID  ${Work ID Owner}.${Work ID Name}
  SOURCETYPE CDL''', imprptpds: '#irpds#(${JOB_ID})', jclgenin: '''//*JCLGEN Input
//STEP1.AJXIN DD *
  PRODUCT  ACM
  WORKID   ${Work ID Owner}.${Work ID Name}
  SSID     ${SSID}''', jcomp: '''${Job Card}
//*
//        JCLLIB ORDER=(#proclib#)
//*
//JOBLIB  DD  DSN=#joblib1#,DISP=SHR
//        DD  DSN=#joblib2#,DISP=SHR
//        DD  DSN=#dsnexit#,DISP=SHR
//        DD  DSN=#dsnload#,DISP=SHR
//***************************************************
// SET ACMDOPT=#dopts#
// SET RTEHLQ=#rtehlq#
// SET USRHLQ=#usrhlq#
//***************************************************
// SET DDLFILE=${Compare2 DDL/Worklist PDS and Member Name}
// SET CDLFILE=${CDL PDS and Member Name}
// SET WORKLIST=${Worklist PDS and Member Name}
// SET EXECJCL=${Execution JCL PDS and Member Name}
// SET IMPRPT=${Impact Report PDS and Member Name}
//*
// SET POFFILE=#pofdsn#
//*----------------------------------------------------
//* BMC CHANGE MANAGER COMPARE
//*----------------------------------------------------
${Compare Input Stream}
//*----------------------------------------------------
//* BMC CHANGE MANAGER IMPORT
//*----------------------------------------------------
//IMPORT   EXEC AMAPROCI,
//    COND=${BMC_COMPARE_COND_CODE}
//IMPORT.IMPORTIN DD DISP=SHR,
//  DSN=&CDLFILE
${Import Input Stream}
//*----------------------------------------------------
//* BMC CHANGE MANAGER ANALYSIS
//*----------------------------------------------------
//ANALYSIS EXEC AMAPROCA,
//    COND=${BMC_COMPARE_COND_CODE}
${Analysis Input Stream}
//*----------------------------------------------------
//* BMC JCL GENERATION
//*----------------------------------------------------
//JCLGEN   EXEC AMAPROCJ,
//    COND=${BMC_COMPARE_COND_CODE}
${JCL Generation Input Stream}''', jobCardIn: '''//DEVOPS JOB (#acctno#),\'COMPARE-${Job_ID}\',
//  class="A",MSGLEVEL=(1,1)
//*
//*
//*''', jobWaitTime: 2, location2: '', moduletype: 'compare1A', nocdl: false, objPart1C1: '', objPart1C2: '', objPart2C1: '', objPart2C2: '', objPart3C1: '', objPart3C2: '', objtyp: 'Select object type', postbaseexec: false, postbasename: '', postbaseprof: '', preBaseType: 'none', prebasename: '', prebaseprof: '', ssid: '${ssid}', useCrule: false, useCruleAfter: false, useCruleBefore: false, wkidname: '${JOB_ID}', wkidowner: 'RDAFJR', wlistpds: '#wlpds#(${JOB_ID})', workIdCommentText: ''
 parameters:
                        [string(name: 'JOB_ID', value: "${params.Job_ID}"),
                         string(name: 'ssid', value: "${params.SSID}"),
                         string(name: 'DDL_DSN', value: "${params.DDL_DSN}")
                        ]
        println "SCHEMA_MIG_RC==" + bmcSM.getRC("BMC_SCHEMA_RC")
}

stage('Validate changed Schema meets Schema Standards') {
bmcAmiSchemaStandards cruleAfterSS: '', debugSS: true, disablebuildstepSS: false, dstream: '''//**********************************************************************
//* The DDs below are used for debugging of Schema Standards
//**********************************************************************
//* $XMLOUT$ contains the objects that will be processed
//SCHEMAS.$XMLOUT$ DD SYSOUT=*
//* $RULETRE contains the rules that will run against the objects
//*SCHEMAS.$RULETRE DD SYSOUT=*
//* $VTIRULE contains the VTI rules that were tested
//*SCHEMAS.$VTIRULE DD SYSOUT=*
//*
//**********************************************************************''', genjclSS: false, inputSchemaSource: '#cdlpds#(${JOB_ID})', jobCardInSS: '''//AMASTDS JOB (#acctno#),\'SCHEMA STANDARDS\',
//  class="A",MSGLEVEL=(1,1)
//**********************************************************************''', jobWaitTimeSS: '2', runModeSS: 'FAIL', sschemaType: 'CDL', ssidSS: '${ssid}', ssjcl: '''${Job Card}
//*
//       JCLLIB ORDER=(#proclib#)
//*
//JOBLIB  DD  DSN=#joblib1#,DISP=SHR
//        DD  DSN=#joblib2#,DISP=SHR
//        DD  DSN=#dsnexit#,DISP=SHR
//        DD  DSN=#dsnload#,DISP=SHR
//*
// EXPORT SYMLIST=(*)
//*
// SET SSID=${SSID}
// SET GUDPLAN=#gudplan#
// SET RULESET=\'${Schema Standards Rule Set name}\'
// SET LOGMODE=${Violation Response}
// SET VTIBSZ=20
//**********************************************************************
//SCHSTDS  EXEC AMAPROCS
${Schema Standards Input Stream}
${Debug Input Stream}''', ssrule: '${Rule_Set}', ssstream: '''//* SOURCETYPE DDL, WORKLIST, CDL INPUT FILE
//SCHEMAS.AMAIN  DD DISP=SHR,DSN=${Input for Schema Source}
//SCHEMAS.ALUIN  DD *,SYMBOLS=JCLONLY
  SSID &SSID
  SOURCETYPE CDL
  RULESET (&RULESET)
  LOGMODE &LOGMODE
  VTIBUCKETSIZE &VTIBSZ
  DEBUG(RULES)''', useCruleAfterSS: false
 parameters:
                        [string(name: 'JOB_ID', value: "${params.Job_ID}"),
                         string(name: 'ssid', value: "${params.SSID}"),
                         string(name: 'Rule_Set', value: "${params.Rule_Set}")
                        ]
        println "SCHEMA_Standards_RC==" + bmcSM.getRC("BMC_SCHEMA_STANDARDS_RC")
}


stage('Common - Clean Up') {
/* clean up workfile */
                    bmcAmiCleanUp()
        }

stage ('Cleanup Workspace and temp dir') {
           /* clean up script tmp directory */
           dir("${workspace}@script@tmp") {
               deleteDir()
           }
           /* clean up script directory */
           dir("${workspace}@script") {
               deleteDir()
           }
   }
 }

  catch (e) {
     currentBuild.result = "FAILED"
     notifyFailed()
     throw e
   }
  }

def notifyFailed() {
    println "SCHEMA_Standards_RC==" + bmcSM.getRC("BMC_SCHEMA_STANDARDS_RC")    
    /* Echo Failure and send Email notification to interested parties */

emailext attachmentsPattern: '*-$BUILD_NUMBER-*Report',
  body: '''*************************** BMC AMI DevOps Schema Standards for Db2 *******************************
 
Jenkins Project: $JOB_NAME
Build#: $BUILD_NUMBER

Check console output at "${BUILD_URL}" to view the results.
         ''', subject: 'Failure - Notification:$JOB_NAME - $BUILD_NUMBER', to: '${Email_on_failure}'

      }


 

Tip: For faster searching, add an asterisk to the end of your partial query. Example: cert*