Deploy MQ on CP4I using Jenkins
Jenkins is a very popular CI/CD tool that allows you to provision applications. In this tutorial, I will show you how to deploy an MQ queue manager, which its configurations to an Red Hat Openshift (using the MQ operators that comes with Cloud Pak for Integration).
Before you begin, you must have the following setup
- Red Hat OpenShift cluster installed (my version is 4.8.21)
- Cloud Pak for Integration installed on the OpenShift cluster (my version is 2021.3.1)
- Github account
- Clone this repository (https://github.com/khongks/mq-pipeline.git)
Install Jenkins on Red Hat OpenShift (from the Openshift Console)
- Create a project called jenkins.
- From the Operator Hub, install jenkins-operator provided by Red Hat in the jenkins namespace. Wait for installation to complete.
3. From the jenkins-operator, create a Jenkins instance. Give a name to your instance (e.g. jenkins-kks). Wait for installation to complete.
4. To access the Jenkins console, get the route using the following command in a terminal.
oc get route -n jenkins jenkins-jenkins-kks -ojson | jq -r .spec.host
You should have the URL for the Jenkins console that looks like this:
jenkins-jenkins-kks-jenkins.<domain-name>
Create a credential in Jenkins to store IBM entitlement key (from Jenkins Console)
- Click on Manage Jenkins > Manage Credentials
2. Click on Jenkins (global) > Global credentials (unrestricted)
3. Click on Add Credentials, with the following setup.
- kind: Secret text
- Scope: Global
- Secret: (obtained from https://myibm.ibm.com/products-services/containerlibrary)
- ID: ibm_entitlement_key
This ID is reference by the Jenkins pipeline to retrieve the value of the Secret.
Enable Jenkins service account to create objects in OpenShift (from terminal)
- Run this command to find the service account in the namespace
oc get sa -n jenkins
The response should be:
NAME SECRETS AGE
builder 2 73m
default 2 73m
deployer 2 73m
jenkins-jenkins-kks 2 54m
jenkins-operator 2 56m
2. Run this command to assign cluster-admin role to the service account. I assigned cluster-admin role, to simplify the setup; but you can create a custom role with the appropriates to do this.
oc adm policy add-cluster-role-to-user cluster-admin system:serviceaccount:jenkins:jenkins-jenkins-kks
Configure a pipeline to build MQ queue manager (from Jenkins Console)
- Click on Dashboard > New Item > Pipeline. Provide a name (e.g. mq-pipeline) and click Ok.
- Go to Pipeline section, specify the following and click Save.
- Definition: Pipeline script from SCM
- SCM: Git
- Repository URL: https://github.com/khongks/mq-pipeline.git
- Branch Specifier: */main
- Script Path: Jenkinsfile
Perform test build (from Jenkins Console)
- Click Build Now.
- Click Build History > #1 > Console Output
- When the pipeline is completed, you should see the following output, with the MQ Console URL, with login user and password. It also generates a ccdt.json to access the queue manager.
...
Installation status: Running
MQ console URL: <<MQ_CONSOLE_URL>>
User: admin
Pass: <<PASSWORD>>
{
"channel": [
{
"name": "QM1CHL",
"clientConnection": {
"connection": [
{
"host": "<<HOST>>",
"port": 443
}
],
"queueManager": "QM1"
},
"transmissionSecurity": {
"cipherSpecification": "ANY_TLS12_OR_HIGHER"
},
"type": "clientConnection"
}
]
}
[Pipeline] }
[Pipeline] // stage
[Pipeline] }[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
4. You should see the status of the completed job (#3 as follows).
Test the deployed queue manager (from terminal)
- Clone the git repository
git clone https://github.com/khongks/mq-pipeline.git
2. Go to the folder mq-pipeline/test and update the file ccdt.json.
3. Put a message.
./mq-put.sh
Sample AMQSPUT0 start
target queue is APPQ
TESTING
4. Get the message
./mq-get.sh
Sample AMQSGET0 start
message <TESTING>
Configure Jenkins pipeline to be triggered from GitHub events
(From the Github web)
- Go to this Github URL to add a webhook
https://github.com/{GIT_ORG}/mq-pipeline/settings/hooks/new
2. Configure Payload URL and Content type
- Payload URL: https://<jenkins-route-hostname>/github-webhook. You can obtain this value from previous step
- Content type: application/json
3. Select event types that triggers this weekhook.
- Pushes
- Pull requests
4. Finally, click on Add webhook to create the webhook.
(From Jenkins console)
5. Click Configure > Build Triggers and check GitHub hook trigger for GITScm polling. Click Save.
6. To test, make a change in the config.mqsc.tmpl file and push the changes into Github repository.
7. Note that build job is triggered in Github.
and in Jenkins.
Hopeful you enjoy this tutorial. Merry Christmas and Happy New Year!
Disclaimer:
All opinions expressed here are very much my own and not of IBM. All codes/scripts/artifacts are provided as-is with no support unless otherwise stated.