zowe / zowe-zdevops-jenkins-plugin

Eclipse Public License 2.0
2 stars 3 forks source link

Zowe zDevOps Jenkins plugin

About the plugin

The Zowe zDevOps Jenkins Plugin by IBA Group is an open-source, secure , and reliable agent-less Jenkins plugin that makes it possible to perform most of the actual tasks on the mainframe, managing it with a modern native mainframe zOSMF REST API and the capabilities of available zOSMF SDKs.

Main features

About us

With over 30 years of experience in the mainframe domain, IBA Group is committed to maximizing your mainframe investment and enhancing your IT flexibility.

One of the services we offer is Mainframe DevOps. Our approach is highly flexible, as we work with customers to choose the essential toolset for establishing a pipeline based on their preferences, existing tools, and the latest open-source opportunities (such as Zowe and plugins).

We are also familiar with Mainframe DevOps Solutions of 2023 that can help modernize your mainframe and keep you competitive.

We value your feedback and welcome any suggestions, proposals, or even complaints.

Please feel free to contact us or schedule a call with our Mainframe DevOps expert.

Thank you for considering IBA Group for your mainframe needs.

Before use - Plugin configuration

After successfully installing the plugin, you need to configure it for further work - this will require a minimum of actions.

  1. Move to 'Manage Jenkins' -> 'Configure System / System' -> scroll to the very bottom of the list of installed plugins and find the panel with the name - 'z/OS Connection List'
  2. This setting allows you to add all necessary z/OS systems and configure access to them. It is necessary to set the connection name (it is also the ID for declarative methods in the code). For the example: z/os-connection-name
  3. The URL address and port of the required mainframe to connect via z/OSMF. Example: https://<ip-addres>:<port number>
  4. Add credentials (Mainframe User ID + Password) under which you can connect to the system.

You can save as many connections as you like, the system will keep the corresponding user IDs/passwords.

Declarative methods brief list

stage ("stage-name") {
  steps {
    // ...
    zosmf("z/os-connection-name") {
        submitJob "//'EXAMPLE.DATASET(MEMBER)'"
        submitJobSync "//'EXAMPLE.DATASET(MEMBER)'"
        downloadDS "EXAMPLE.DATASET(MEMBER)"
        downloadDS dsn:"EXAMPLE.DATASET(MEMBER)", vol:"VOL001"
        allocateDS dsn:"EXAMPLE.DATASET", alcUnit:"TRK", dsOrg:"PS", primary:1, secondary:1, recFm:"FB"
        writeFileToDS dsn:"EXAMPLE.DATASET", file:"workspaceFile"
        writeFileToDS dsn:"EXAMPLE.DATASET", file:"D:\\files\\localFile"
        writeToDS dsn:"EXAMPLE.DATASET", text:"Write this string to dataset"
        writeFileToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", file:"workspaceFile"
        writeFileToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", file:"D:\\files\\localFile"
        writeToMember dsn:"EXAMPLE.DATASET", member:"MEMBER", text:"Write this string to member"

        writeToFile destFile: "u/USER/myfile", text: "Write this string to file"
        writeFileToFile destFile: "u/USER/myfile", sourceFile: "myfile.txt"
        writeFileToFile destFile: "u/USER/myfile", sourceFile: "myfile.txt", binary: "true"

        deleteDataset dsn:"EXAMPLE.DATASET"
        deleteDataset dsn:"EXAMPLE.DATASET", member:"MEMBER"
        deleteDatasetsByMask mask:"EXAMPLE.DATASET.*"
    }
    // ...
  }
}

Declarative Methods Detail Description

allocateDS - Represents an action for allocating a dataset in a declarative style

zosmf ("z/os-connection-name") {
    allocateDS(
        // Mandatory Parameters below:
        dsn: "EXAMPLE.DATASET",
        dsOrg: "PS",
        primary: 1,
        secondary: 1,
        recFm: "FB",
        // Optional Parameters below:
        volser:"YOURVOL",
        unit:"SYSDA",
        alcUnit:"TRK",
        dirBlk:"5",
        blkSize:"800",
        lrecl:"80",
        storClass:"STORAGECLASS",
        mgntClass:"MGMTCLASS",
        dataClass:"DATACLASS",
        avgBlk:"10",
        dsnType:"LIBRARY",
        dsModel:"MODEL.DATASET.NAME"
    )
}

Mandatory Parameters:

Optional parms:

deleteDataset - Represents an action for deleting datasets and members in a declarative style

zosmf ("z/os-connection-name") {
    deleteDataset dsn: "EXAMPLE.DATASET", member:"MEMBER"
}

Mandatory Parameters:

Expected behavior under various deletion scenarios:

Use case example

Here you can find an example of a minimal declarative Jenkins pipeline for execution, testing and further modification for your personal needs. Pipeline can be used either directly inside the Pipeline code block in the Jenkins server, or in a Jenkinsfile stored in Git This pipeline example uses all currently available methods and functionality of the Zowe zDevOps plugin.

Steps to Execute the Pipeline:

  1. Add a zosmf connection in settings ('Manage Jenkins' -> 'Configure System / System' -> z/OS Connection List). Enter a connection name, zosmf url, username and password.
  2. Create a new Jenkins item -> Pipeline and open its configuration.
  3. In the Pipeline section, paste the code from the example below and replace all the necessary variables with your data
  4. Done, enjoy the minimal ready-made pipeline template!
pipeline {
    agent any

    environment {
        // Define environment variables
        GIT_REPOSITORY_URL = 'https://github.com/your-username/your-repo.git'  // Replace with your GitHub URL
        GIT_BRANCH = 'main'                                     // Replace with your GitHub branch name
        GIT_USER_CREDENTIAL_ID = 'jenkins-cred-key'             // Replace with your Jenkins GitHub credential ID
        ZOS_CONN_ID = 'z/os-connection-name'                    // Replace with your z/OS Connection ID from zDevOps plugin settings
        HLQ = 'HLQ'                                             // Replace with your z/OS high-level qualifier (HLQ)
        PS_DATASET_1 = "${HLQ}.NEW.TEST1"                       // OPTIONAL: Replace with the dataset names you need
        PS_DATASET_2 = "${HLQ}.NEW.TEST2"                       // OPTIONAL
        PO_DATASET = "${HLQ}.NEW.TEST3"                         // OPTIONAL
        PO_MEMBER = "NEWMEM"                                    // OPTIONAL
        JCL_JOB_TEMPLATE = "jcl_job_example"                    // Replace with the name of your file that contains the JCL job code
        JIRA_URL = 'https://your-jira-instance.atlassian.net'   // Replace with your Jira URL
        JIRA_USER = 'your-jira-email@example.com'               // Replace with your Jira user email
        JIRA_API_TOKEN = 'your-jira-api-token'                  // Replace with your Jira API token
        JIRA_ISSUE_KEY = 'PROJECT-123'                          // Replace with your Jira issue key
    }

    stages {
        stage('Checkout') {
            steps {
                // Checkout the source code from Git
                checkout scmGit(
                    branches: [[name: "${GIT_BRANCH}"]],
                    userRemoteConfigs: [[credentialsId:  "${GIT_USER_CREDENTIAL_ID}",
                    url: "${GIT_REPOSITORY_URL}"]])
            }
        }

        stage('Allocate DSs') {
            steps {
                zosmf("${ZOS_CONN_ID}") {
                    allocateDS dsn:"${PS_DATASET_1}", dsOrg:"PS", primary:1, secondary:1, recFm:"FB"
                    allocateDS dsn:"${PS_DATASET_2}", dsOrg:"PS", primary:1, secondary:1, recFm:"FB", alcUnit:"TRK"
                    allocateDS dsn:"${PO_DATASET}(${PO_MEMBER})", dsOrg:"PO", primary:1, secondary:1, recFm:"FB"
                }
            }
        }

        stage('Add JCL content') {
            steps {
                script {
                   // Read the content of the JCL job into a variable
                   env.JCL_CONTENT = readFile("${JCL_JOB_TEMPLATE}").trim()
                   // Print the content of the file (for debugging purposes)
                   echo "JCL job content:\n${env.JCL_CONTENT}"
                }
                zosmf("${ZOS_CONN_ID}") {
                    writeFileToDS dsn:"${PS_DATASET_2}", file:"${JCL_JOB_TEMPLATE}"
                    writeFileToMember dsn:"${PO_DATASET}", member:"${PO_MEMBER}", file:"${JCL_JOB_TEMPLATE}"
                    writeToDS dsn:"${PS_DATASET_1}", text:"${env.JCL_CONTENT}"
                }
            }
        }

        stage('Add USS content') {
            steps {
                zosmf("${ZOS_CONN_ID}") {
                    writeToFile destFile: "u/${HLQ}/test_file1", text: "${env.JCL_CONTENT}"
                    writeFileToFile destFile: "u/${HLQ}/test_file2", sourceFile: "${JCL_JOB_TEMPLATE}", binary: "true"
                }
            }
        }

        stage('Submit JCL jobs') {
            steps {
                zosmf("${ZOS_CONN_ID}") {
                    submitJob "//'${PS_DATASET_1}'"
                    submitJobSync "//'${PO_DATASET}(NEWMEM)'"
                }
            }
        }

        stage('Download datasets') {
            steps {
                zosmf("${ZOS_CONN_ID}") {
                    downloadDS "${PS_DATASET_1}"
                    downloadDS dsn:"${PS_DATASET_2}"
                }
            }
        }

        stage('Clean up') {
            steps {
                zosmf("${ZOS_CONN_ID}") {
                    deleteDataset dsn:"${PS_DATASET_1}"
                    deleteDatasetsByMask mask:"${HLQ}.NEW.*"
                }
            }
        }
    }

    post {
        always {
            script {
                def jiraStatus = currentBuild.currentResult == 'SUCCESS' ? 'Build Successful' : 'Build Failed'
                def jiraComment = """
                {
                    "body": "Jenkins build ${jiraStatus} for Job ${env.JOB_NAME} - Build #${env.BUILD_NUMBER}.
                    [View the build here|${env.BUILD_URL}]"
                }
                """

                httpRequest acceptType: 'APPLICATION_JSON',
                            contentType: 'APPLICATION_JSON',
                            httpMode: 'POST',
                            requestBody: jiraComment,
                            url: "${JIRA_URL}/rest/api/2/issue/${JIRA_ISSUE_KEY}/comment",
                            authentication: 'jira-credentials-id'
            }
        }

        success {
            // Notify success (example: send email)
            mail to: '${JIRA_USER}',
                 subject: "SUCCESS: Build ${env.BUILD_NUMBER}",
                 body: "The build ${env.BUILD_NUMBER} was successful."
        }

        failure {
            // Notify failure (example: send email)
            mail to: '${JIRA_USER}',
                 subject: "FAILURE: Build ${env.BUILD_NUMBER}",
                 body: "The build ${env.BUILD_NUMBER} failed. Please check the Jenkins logs for more details."
        }
    }
}

Manual plugin installation by the .hpi executable file

The plugin are packaged as self-contained .hpi files, which have all the necessary code, images, and other resources which the plugin needs to operate successfully.

Already packaged and tested installation .hpi file can be downloaded from a link from a nearby GitHub repository:

Zowe zDevOps plugin installation .hpi file

Assuming a .hpi file has been downloaded, a logged-in Jenkins administrator may upload the file from within the web UI:

  1. Navigate to the Manage Jenkins > Plugins page in the web UI.
  2. Click on the Advanced tab.
  3. Choose the .hpi file from your system or enter a URL to the archive file under the Deploy Plugin section.
  4. Deploy the plugin file.

Manual Jenkins plugin installation (Installation via source code build and .hpi file upload)

  1. Download the Zowe zDevOps Jenkins plugin source code from its official GitHub repository
  2. It is necessary to build the project with the help of the Maven Build Tool
  3. To generate the target dir with generated-sources - you have to run the Maven command: mvn localizer:generate
  4. Next, you need to generate an installation file: .hpi or .jpi file (both are installation files for the Jenkins plugin). This can be done by executing Maven command mvn install or by mvn hpi:hpi.
  5. After building the .hpi/.jpi file, it should appear in a /build/libs/.hpi directory
  6. Next you need to login into the Jenkins, move to the 'Manage Jenkins' -> 'Plugins' -> 'Advanced settings (tab)' -> 'Deploy Plugin' (You can select a plugin file from your local system or provide a URL to install a plugin from outside the central plugin repository) -> Specify the path to the generated .hpi/.jpi file (or by dragging the file from Intellij IDEA project to the file upload field in the Jenkins).
  7. Click 'Deploy', reboot Jenkins after installation. The Plugin is ready to go!

How to run Jenkins plugin in Debug mode in a local Jenkins sandbox

For debugging purposes run following Maven command from plugin project directory:

./mvnw hpi:run

Or by mvnDebug hpi:run - this will copy all the dependencies down (rather than in your jenkins install) and run it in place.

By default, the debugging instance is then available at http://localhost:8080/jenkins in your browser.

In order to launch Jenkins on a different port than 8080 use this system property:

./mvnw hpi:run -Djetty.port=8090

Changing the default context path can be achieved by setting this system property:

./mvnw hpi:run -Dhpi.prefix=/debug

How to run unit-tests with JaCoCo report

./mvnw clean verify

The results are available under target/site/jacoco/index.html