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.
Install Workbench for Eclipse CLI version 23.02.01 or later on Windows or Linux. See Workbench for Eclipse Installation Guide
- Update Jenkins configuration for the Workbench for Eclipse CLI
- On the Jenkins home page, select Jenkins
- Select Manage Jenkins > Configure System and set up the Workbench CLI location and a host connection. See Common configurations.
- Install BMC Compuware Common Configurations Jenkins. See BMC plugins.
- 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.
- In Workbench for Eclipse, open the Code Pipeline perspective.
- From the Window menu, select Open Perspective>Other. The Open Perspective dialog box appears.
Select Code Pipeline and click OK. The Code Pipeline Repository Explorer view appears.
- 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.
Click Apply. A filtered list of the components within the PLAY application appears.
Task 3: Creating a new Git repository named IspwGitPlayTest
To create a new repository:
- Go to the Git Server.
To create a personal repository, click your profile and select View profile, then select Create repository.
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
- In Workbench for Eclipse’s Project Explorer view, from the File menu, select New>Project. The New Project wizard appears.
- Toggle open the General node, select Project, and click Next. The New Project page appears.
- In the Project name field, enter GitPlay and click Finish.
Configuring the Code Pipeline and Git mapping
- In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node and select Configure>Configure to Use Code Pipeline.
- 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.
- In the Runtime Configuration field, enter the runtime configuration if not using the default Code Pipeline instance.
- Click Next. The next page of the wizard appears.
- From the Stream list, select PLAY.
- From the Application list, select PLAY.
- From the Sub-Application list, select PLAY.
- From the Level list, select the level used when doing a build.
- From the Download source from path list, choose the level from which to download source for the project.
- 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.
- 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
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- 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:
- 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.
- Select the project from the list.
- Click Use or create repository in parent folder of project.
- Click Create Repository.
- Click Finish.
Task 6: Creating a multibranch pipeline project using the Jenkinsfile
You can create a multibranch pipeline project by performing the following steps:
- In the Jenkins UI, click Jenkins and select New Item.
- In the Enter an item name field, enter the name for a multi-branch pipeline project.
- Select Multibranch Pipeline for the list.
- Click OK.
- Alternatively, on the General tab for configuring the pipeline just created, enter the display name and description.
- Select the Branch Sources tab, click Add source, and select Git from the list.
- 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.
- 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.
- 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
for use.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
'''
}
}
- Launch a text editor.
Copy the script from the example above and paste it into an empty text file. It will be customized in the following steps.
- In Jenkins, navigate to the Jenkins multibranch pipeline project.
- From the project’s left pane, select Pipeline Syntax. The Snippet Generator appears.
- 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.
In the Branch Mapping field, enter *Play* => DEV1, per-branch.
- Complete the rest of the fields, referring to the available help as needed.
Click Generate Pipeline Script. The generated script appears below the Generate Pipeline Script button.
- Copy and paste the generated script within the second stage in the text file, replacing all code between the curly braces for that stage.
- 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.
- In the Action field, select BuildAssignment.
In the Request field, specify the following:
buildautomatically=true- Complete the rest of the fields, referring to the available help as needed.
- Click Generate Pipeline Script. The generated script appears below the Generate Pipeline Script button.
- Copy and paste the generated script within the third stage in the text file, replacing all code between the curly braces for that stage.
- In the text editor, from the File menu, click Save. The Save As dialog box appears.
- 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” - Click Save.
Task 8: Importing a Jenkinsfile to the Root Directory of the GitPlay project
- In Workbench for Eclipse’s Project Explorer view, right-click the GitPlay project node.
- Select Import. The Import wizard appears.
- Select General>File System and click Next. The File system page appears.
- In the From directory field, browse to the folder location of the Jenkinsfile.
- Select the Jenkinsfile in the right pane.
Click Finish. The Jenkinsfile appears at the root of the GitPlay project in the Project Explorer view.
Task 9: Committing and Push the GitPlay project to the Master branch in the IspwGitPlayTest repository
- In Workbench for Eclipse, open the Git perspective.
- 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.
- If there is no repository selected in the Git Staging view, click
and select GitPlay to switch to the GitPlay repository.
- In the Unstaged Changes box, select all of the components and click
to add them to the Staged Changes box.
- In the Commit Message box, enter a commit message, such as Commit to master.
- Click Commit and Push.
- 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.
- In the Push Results dialog, click Close.
Task 10: Making a change and building
- Switch to a new branch named PlayBranch1 by performing the following steps.
- 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.
- In the Branch name field, specify PlayBranch1 as the branch name.
- Click Finish.
- Verify that GitPlay project node in Project Explorer is now set to PlayBranch1.
- Make a change to Cobol Component TPROG01.cob
- In Workbench for Eclipse’s Project Explorer view, expand GitPlay>COB.
- Right-click TPROG01.cob and select Open. The source opens in the editor.
On line 3, change the Author from BENCHMARK
Code Pipeline
TRAINING to BENCHMARK
Code Pipeline
TRAINING1.
- From the File menu, select Save.
- From the File menu, select Close.
- Perform the Build Action to verify the source generates successfully along with any impacted components.
- 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.
- In the YAML mapping file location field, enter or browse to the YAML mapping file.
- 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.
- 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}.
- Click Apply and Close.
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.
- 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.
- Update the Jenkinsfile Build Code Pipeline assignment stage.
- In Workbenh for Eclipse’s Project Explorer view’s GitPlay project, right-click Jenkinsfile and select Open. The source opens in the editor.
- In the Build Code Pipeline assignment stage, verify that the ispwRequestBody reads “‘buildautomatically=true’”.
- From the File menu, select Save.
- From the File menu, select Close.
Task 11: Submitting change to pipeline
- 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.
- Commit and Push the Jenkinsfile
- In Workbench for Eclipse, open the Git perspective’s Git Staging view.
- If the Git Staging view is not set to the GitPlay repository, click
and select GitPlay to switch to the GitPlay repository.
- In the Unstaged Changes box, select the Jenkinsfile file and click
to add it to the Staged Changes box.
- In the Commit Message box, enter a commit message, such as Jenkinsfile commit.
- Click Commit and Push. The Push Results dialog box appears.
- Click Close.
- Commit and Push TPROG01
- In the Unstaged Changes box, select TPROG01 and click
to add it to the Staged Changes box.
- In the Unstaged Changes box, select TPROG01 and click
- In the Commit Message box, enter a commit message, such as TPROG01 commit.
- The Push Results dialog box appears.
- 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.
- 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.
- 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):
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):
TPROG01 has been compiled successfully
1 of 1 generated successfully. 0 of 1 generated with errors.
The build process was successfully completed.
Task 13: Verifying the updates occurred to the Mainframe
- 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.
Double-click TPROG01. The source is opened in the editor.
- Verify that line 3 shows BENCHMARK Code Pipeline TRAINING1 for Author.
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.
- In Workbench for Eclipse Project Explorer, find the Git project where copybook concatenation list will be configured.
- Right click on the project then click on Properties.
- Within the properties, click on the arrow next to the Code Pipeline node, followed by clicking on Copybook Concatenation.
- 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.
- Within the Copybook Concatenation window, you can select all or partial projects from the list. Click OK when you are finished selecting your projects.
- 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.