Integrating Git to Code Pipeline for Jenkins


This topic describes in detail, all the tasks that you need to perform to synchronize Git and Code Pipeline when you are using the Jenkins orchestrator.

Task 1: Installing the required plugins in Workbench for Eclipse and Jenkins

This step provides you with instructions to install the required plugins.

  • Install EGit. For more information on the installation process, see Egit download manual.
  • Install Jenkins. Perform the following steps to install Jenkins.
    1. Install Workbench for Eclipse CLI version 23.02.01 or later on Windows or Linux. See Workbench for Eclipse Installation Guide

      1. Update Jenkins configuration for the Workbench for Eclipse CLI
      2. On the Jenkins home page, select Jenkins
      3. Select Manage Jenkins > Configure System and set up the Workbench CLI location and a host connection. See Common configurations.
    2. Install BMC Compuware Common Configurations Jenkins. See BMC plugins.
    3. Install Code Pipeline Operations Jenkins plugin. See BMC plugins.

Task 2: Verifying if the Code Pipeline mainframe PLAY application is available

The Code Pipeline PLAY application is installed as a part of the Training Application delivered in the Code Pipeline SAMPLIB in the Installation Verification Process (IVP).

Perform the following steps to install the PLAY application instance based on your host connection. If you are unable to locate the PLAY application, refer Installation Verification Procedures in the Code Pipeline Installation and Configuration guide.

  1. In Workbench for Eclipse, open the Code Pipeline perspective.
  2. From the Window menu, select Open Perspective>Other. The Open Perspective dialog box appears.
  3. Select Code Pipeline and click OK. The Code Pipeline Repository Explorer view appears.

    Important

    The Code Pipeline Repository Explorer view is visible by default. If it is not visible:

    1. From the Window menu, select Show View>Other. The Show View dialog box appears.
    2. Open Code Pipeline, select the Code Pipeline Repository Explorer view, and click OK.
  4. In the Code Pipeline Repository Explorer select the following:
    • From the Stream list, select PLAY.
    • From the Application list, select PLAY.
    • From the Sub-Application list, select PLAY.
    • From the Level list, select DEV1.
    • From the Level option list, select First found in level and above.
  5. Click Apply. A filtered list of the components within the PLAY application appears.

    Tip

    If you are not logged onto a host connection where the Code Pipeline PLAY application is installed, you will be prompted when you select any list in the Code Pipeline Repository Explorer view.

Task 3: Creating a new Git repository named IspwGitPlayTest

To create a new repository:

  1. Go to the Git Server.
  2. To create a personal repository, click your profile and select View profile, then select Create repository.
    ISPWDetailedSteps_3.png

    Tip

    Depending on the Git server (GitHub, Bitbucket, etc.) and interface (web, desktop, etc.) you are using, the nomenclature and way to create a new repository may differ from what is shown here. Refer to your Git server's online help.

Task 4: Setting up a Git Project with the Source, YAML File, and Jenkinsfile

This task provides information about how to create GitPlay project and map Code Pipeline with Git.

Creating a new general project called GitPlay and importing the Code Pipeline Project source

  1. In Workbench for Eclipse’s Project Explorer view, from the File menu, select New>Project. The New Project wizard appears.
  2. Toggle open the General node, select Project, and click Next. The New Project page appears.
  3. In the Project name field, enter GitPlay and click Finish.

Configuring the Code Pipeline and Git mapping

  1. In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node and select Configure>Configure to Use Code Pipeline.
  2. From the Host list, select the host where the PLAY application is located, or click Configure to configure a host. We recommend you use the fully qualified domain name when configuring the host.
  3. In the Runtime Configuration field, enter the runtime configuration if not using the default Code Pipeline instance.
  4. Click Next. The next page of the wizard appears.
  5. From the Stream list, select PLAY.
  6. From the Application list, select PLAY.
  7. From the Sub-Application list, select PLAY.
  8. From the Level list, select the level used when doing a build.
  9. From the Download source from path list, choose the level from which to download source for the project.
  10. In the YAML mapping file location field, enter or browse to the project folder in which to create the YAML mapping file. By default, the location is the root of project.
  11. Click Finish. The source is downloaded. The ispwconfig.yml file is created and added to the root of the GitPlay project in the Project Explorer view. The Console view shows the activity, and the Project Explorer view shows the downloaded files. You can Download the template for use.
    ISPWDetailedSteps_1_rebranded.png

  12. To examine the contents of the ispwconfig.yml file, right-click the file and select Open.

    !!com.compuware.ispw.cli.model.IspwRoot
       ispwApplication:
       application: PLAY
      host: somehost.example.com
       pathMappings:
      - path: \CLST
       types:
      - fileExtension: clst
       ispwType: CLST
         - path: \COB
       types:
      - fileExtension: cob
       ispwType: COB
         - path: \COPY
       types:
      - fileExtension: copy
       ispwType: COPY
         - path: \JOB
       types:
      - fileExtension: job
       ispwType: JOB
          port: 12345
          runtimeConfig: TPZP
          stream: PLAY
  13. For information on the available Code Pipeline property settings and path mappings, see Git to Code Pipeline integration - the Code Pipeline YAML configuration file.

Task 5: Sharing the GitPlay project as a Git repository to convert the Code Pipeline project to a Git project

To share the GitPlay project as a Git repository:

  1. In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node and select Team>Share Project. The Share Project dialog box appears.
  2. Select the project from the list.
    ISPWDetailedSteps_2.png
  3. Click Use or create repository in parent folder of project.
  4. Click Create Repository.
  5. Click Finish.

Task 6: Creating a multibranch pipeline project using the Jenkinsfile

You can create a multibranch pipeline project by performing the following steps:

  1. In the Jenkins UI, click Jenkins and select New Item.
  2. In the Enter an item name field, enter the name for a multi-branch pipeline project.
  3. Select Multibranch Pipeline for the list.
  4. Click OK.
  5. Alternatively, on the General tab for configuring the pipeline just created, enter the display name and description.
  6. Select the Branch Sources tab, click Add source, and select Git from the list.
  7. In the Project Repository field, enter the project repository URL and, in the Credentials field, enter the credentials if the account is private. The project repository URL can be found in the Git server Repository Settings of the IspwGitPlayTest repository in the Name field.
  8. Select the Build Configuration tab. The Mode field should already be set to Jenkinsfile and the Script Path should be set to Jenkinsfile. In a later step, the Jenkinsfile will be created at the root of the project where this setting expects it to be located. Therefore, do not make any further changes on this tab. Select the Scan Multibranch Pipeline Triggers Tab. Select the Periodically if not otherwise run check box and set the Interval field to 1 minute.
  9. Click Save. A Scan Multibranch Pipeline Log appears. If the pipeline was set up correctly, Finished: SUCCESS will appear at the end of the log.

Task 7: Creating a Jenkinsfile

This step implements a Jenkins pipeline within a Jenkinsfile. The Jenkinsfile is broken up into three stages:

  • Checkout - checks out the source code.
  • Git to Code Pipeline Synchronization - performs the Git to Code Pipeline synchronization.
  • Build Code Pipeline assignment - performs a build.

The following is an example of the Jenkinsfile. You can Download the template for use.

node {
  stage ('Checkout')
 {
   // Get the code from the Git repository
    checkout scm
 }

  stage('Git to ISPW Synchronization')
 {
gitToIspwIntegration app: 'PLAY',
branchMapping: '''*Play* => DEV1, per-branch''',
connectionId: '9079999f-ab78-4047-8366-00eb8aa4f173',
credentialsId: 'ce986ae7-1b4d-4f0d-8f9b-a0b022182124',
gitCredentialsId: 'loginToGit3',
gitRepoUrl: ''https://host:port/path/ispwgitplaytest.git',
runtimeConfig: '
TPZP',
stream: '
PLAY'
  }

  stage('
Build ISPW assignment')
  {
ispwOperation connectionId: '
9079999f-ab78-4047-8366-00eb8aa4f173',
consoleLogResponseBody: true,
credentialsId: '
your-credential-id.1conn',
ispwAction: '
BuildAssignment',
ispwRequestBody: '''
buildautomatically = true
'''
 }
}
  1. Launch a text editor.
  2. Copy the script from the example above and paste it into an empty text file. It will be customized in the following steps.

    Important

    You do not have to customize the first stage, Checkout, for this tutorial as it does a checkout scm, which is Jenkins’ out-of-the-box method for exiting code in the pipeline. It can, however, be customized using the Snippet Generator’s checkout: Check out from version control.

  3. In Jenkins, navigate to the Jenkins multibranch pipeline project.
  4. From the project’s left pane, select Pipeline Syntax. The Snippet Generator appears.
    ISPWDetailedSteps_4.png
  5. To begin defining the syntax for the second stage, Git to Code Pipeline synchronization, in the Sample Step field, select gitToIspwIntegration: Git to Code Pipeline Integration.
    ISPWDetailedSteps_5.png
  6. In the Branch Mapping field, enter *Play* => DEV1, per-branch.

    Tip

    The first field in the branch mapping (*Play*) is part of the branch name PlayBranch1, which will be used to do the commit and push in a later step. Therefore, it is important that the mapping matches the branch name or part of the branch name with a wildcard for the multibranch pipeline project to be completed successfully.

  7. Complete the rest of the fields, referring to the available help as needed.
  8. Click Generate Pipeline Script. The generated script appears below the Generate Pipeline Script button.
    ISPWDetailedSteps_6.png

    Important

    For Code Pipeline Operations Jenkins plugin version 1.0.7 or earlier, if any user ID or login credentials are present at the beginning of the Git repository URL, remove them. 

  9. Copy and paste the generated script within the second stage in the text file, replacing all code between the curly braces for that stage.
  10. To begin defining the syntax for the third stage, Build Code Pipeline assignment, in the Snippet Generator’s Sample Step field, select ispwOperation: Perform a Compuware Code Pipeline REST API Request and return a JSON object.
    ISPWDetailedSteps_7.png
  11. In the Action field, select BuildAssignment.
  12. In the Request field, specify the following:

    buildautomatically=true
  13. Complete the rest of the fields, referring to the available help as needed.
  14. Click Generate Pipeline Script. The generated script appears below the Generate Pipeline Script button.
    ISPWDetailedSteps_8.png
  15. Copy and paste the generated script within the third stage in the text file, replacing all code between the curly braces for that stage.
  16. In the text editor, from the File menu, click Save. The Save As dialog box appears.
  17. In the File name field, enter the following, exactly as shown and including quotation marks to create the file without an extension. The file name is case-sensitive.
    “Jenkinsfile”
  18. Click Save.

Important

Starting with v1.09, the Code Pipeline Jenkins Operations plugin can support certificates to connect with Code Pipeline. For information about using certificates with Jenkins, see Using credentials.

Task 8: Importing a Jenkinsfile to the Root Directory of the GitPlay project

  1. In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node.
  2. Select Import. The Import wizard appears.
  3. Select General>File System and click Next. The File system page appears.
  4. In the From directory field, browse to the folder location of the Jenkinsfile.
    ISPWDetailedSteps_9.png
  5. Select the Jenkinsfile in the right pane.
  6. Click Finish. The Jenkinsfile appears at the root of the GitPlay project in the Project Explorer view.
    ISPWDetailedSteps_10_rebranded.png

    Tip

    It is important to ensure that the Jenkinsfile is located at the project root, where the multibranch pipeline project’s configuration Script Path field expects it to be.

Task 9: Committing and Push the GitPlay project to the Master branch in the IspwGitPlayTest repository

  1. In Workbench for Eclipse, open the Git perspective.
  2. If the Git Staging view is not visible, from the Window menu, select Show View>Other. The Show View dialog box appears. Select Git>Git Staging, and click Open.
  3. If there is no repository selected in the Git Staging view, click GitHub_icon_gitplay.pngand select GitPlay to switch to the GitPlay repository.
  4. In the Unstaged Changes box, select all of the components and click GitHub_icon_GitStagingAddAll.pngto add them to the Staged Changes box.
    ISPWDetailedSteps_11.png
  5. In the Commit Message box, enter a commit message, such as Commit to master.
  6. Click Commit and Push.
  7. If the Push Branch master dialog box appears, in the URI field, specify the URL of the IspwGitPlayTest repository. The repository URL can be found in the Git server Repository Settings of the IspwGitPlayTest repository under the Name field. Complete the rest of the fields if not automatically populated. Click Next to select the remote repository. The repository name should contain the branch name. Click Next again to confirm the expected push result, then click Finish.
    ISPWDetailedSteps_12.png
  8. In the Push Results dialog, click Close.
    ISPWDetailedSteps_13.png

Task 10: Making a change and building

  1. Switch to a new branch named PlayBranch1 by performing the following steps.
    1. In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node and select Team>Switch To>New Branch. The Create Branch dialog box appears.
    2. In the Branch name field, specify PlayBranch1 as the branch name.
    3. Click Finish.
    4. Verify that GitPlay project node in Project Explorer is now set to PlayBranch1.
      ISPWDetailedSteps_14a_rebranded.png
  2. Make a change to Cobol Component TPROG01.cob
    1. In Workbench for Eclipse’s Project Explorer view, expand GitPlay>COB.
    2. Right-click TPROG01.cob and select Open. The source opens in the editor.
    3. On line 3, change the Author from BENCHMARK 

      Code Pipeline

       TRAINING to BENCHMARK 

      Code Pipeline

       TRAINING1.
      ISPWDetailedSteps_15.png

    4. From the File menu, select Save.
    5. From the File menu, select Close.
  3. Perform the Build Action to verify the source generates successfully along with any impacted components.
    1. In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node and select Properties>Code Pipeline. The Code Pipeline page of the Properties dialog box appears.
    2. In the YAML mapping file location field, enter or browse to the YAML mapping file.
    3. In the Level field, enter DEV1 as the life cycle level for the project that will be used to load the file into Code Pipeline at that level. The level value is required to perform any Code Pipeline action.
    4. Optionally, in the Assignment description field, enter the assignment name to be used for the generate/build process; click Insert Variable, if desired, to choose variables to build the assignment name. Note that, if no valid value exists for the chosen variable, the Description field in the Containers view will treat the variable as empty, Descriptions longer than 50 characters will be truncated. The default assignment description is ${user} ${branch_name}.
    5. Click Apply and Close.
    6. In the Project Explorer view’s COB folder, right-click TPROG01.cob and select Code Pipeline>Build. The Console view shows the progress of the build.

      Important

      If an Code Pipeline pop-up appears, click **YES** to continue. :::


      ISPWDetailedSteps_16.png

    7. In the Console view, note the assignment where TPROG01 was loaded. In the example above, TPROG01 was loaded into assignment PLAY003136 at the DEV1 level.
  4. Update the Jenkinsfile Build Code Pipeline assignment stage.
    1. In Workbenh for Eclipse’s Project Explorer view’s GitPlay project, right-click Jenkinsfile and select Open. The source opens in the editor.
    2. In the Build Code Pipeline assignment stage, verify that the ispwRequestBody reads “‘buildautomatically=true’”.
      ISPWDetailedSteps_17.png
    3. From the File menu, select Save.
    4. From the File menu, select Close.

Task 11: Submitting change to pipeline

  1. Commit and push the changes to Git. First commit and push only the Jenkinsfile so the updated assignmentId is used for the change to TPROG01. Then commit and push TPROG01.
  2. Commit and Push the Jenkinsfile
    1. In Workbench for Eclipse, open the Git perspective’s Git Staging view.
    2. If the Git Staging view is not set to the GitPlay repository, click GitHub_icon_gitplay.pngand select GitPlay to switch to the GitPlay repository.
    3. In the Unstaged Changes box, select the Jenkinsfile file and click GitHub_icon_GitStagingAdd.pngto add it to the Staged Changes box.
      ISPWDetailedSteps_18.png
    4. In the Commit Message box, enter a commit message, such as Jenkinsfile commit.
    5. Click Commit and Push. The Push Results dialog box appears.
    6. Click Close.
  3. Commit and Push TPROG01
    1. In the Unstaged Changes box, select TPROG01 and click GitHub_icon_GitStagingAdd.pngto add it to the Staged Changes box.
      ISPWDetailedSteps_19.png

    1. In the Commit Message box, enter a commit message, such as TPROG01 commit.
    2. The Push Results dialog box appears.
    3. Click Close.


Task 12: Determining if synchronization process completed successfully

Two jobs will be triggered for the Jenkins multibranch pipeline project within a one-minute interval: one job when the Jenkinsfile was pushed and one job when TPROG01 was pushed.

  1. In Jenkins, examine the second job. In the multibranch pipeline project, in the Branches section, select PlayBranch1. Within the Pipeline PlayBranch1, go to the Build History section where the jobs are listed.
  2. Once the job completes, go to the Console Output. The Console Output link is in the multibranch pipeline project’s sidebar.

The following is an example of what the Console Output will show for a successful Git to Code Pieplime synchronization (the second stage of the Jenkinsfile):

Finished synchronizing changes from Git to ISPW assignment PLAY003145 at level DEV1
COB/TPROG01.cob     ----- Success
1 total changes detected during synchronization: Success 1, Failure 0, Skipped 0

The following is an example of what the Console Output will show for a successful build (the third stage of the Jenkinsfile):

1 task will be built as part of S000183395
TPROG01 has been compiled successfully
1 of 1 generated successfully. 0 of 1 generated with errors.
The build process was successfully completed.

Tip

Git commit information can be viewed in Workbench within the Code Pipeline Assignment view and the Code PipelineRelease view.

Task 13: Verifying the updates occurred to the Mainframe

  1. In Workbech for Eclipse’s Code Pipeline Containers view, find the assignment where TPROG01 was loaded and double-click the assignment. The Code Pipeline Tasks view appears.
  2. Double-click TPROG01. The source is opened in the editor.

    Important

    If a copybook download message appears, click No to not download copybooks.

  3. Verify that line 3 shows BENCHMARK Code Pipeline TRAINING1 for Author.
    ISPWDetailedSteps_20.png

Task 15: Configuring a copybook concatenation list for a Git project

By configuring a copybook concatenation list, your programs will download the correct copybooks defined by the project list in the order they are provided. The copybooks are only downloaded upon opening a component from the project explorer view, or if the Download Copybooks context menu option is selecting when right clicking from the editor itself.

Tip

Before configuring a copybook concatenation list, it is a good idea to have your other Git projects already created/imported into your workspace. These other Git projects will be candidate for selection during the copybook concatenation configuration.

  1. In Workbench for Eclipse Project Explorer, find the Git project where copybook concatenation list will be configured.
  2. Right click on the project then click on Properties.
  3. Within the properties, click on the arrow next to the Code Pipeline node, followed by clicking on Copybook Concatenation.
  4. On the right-hand side, click on the Add... button. Another window titled Copybook Concatenation will display with all the other projects that have been configured to utilize the Code Pipeline Nature. The nature of the project can change in the same properties window within the Project Natures node.
  5. Within the Copybook Concatenation window, you can select all or partial projects from the list. Click OK when you are finished selecting your projects.
  6. In the properties window, you should now see the Git projects you selected in the previous step. You can also arrange the ordering of the projects by selecting one and clicking on the Move Up or Move Down buttons on the right-hand side.
    ISPWDetailedSteps_21.png


Tip

The ordering of the Git projects is important. During the copybook download process, the copybook is downloaded according to the ordering of the configured list of projects. For example, if you have configured your concatenation list to include projects test1 & test2, the copybook download process will first look for the referenced copybook in test1 and if not found, it will finally check within test2.




 

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