Search This Blog

Friday, November 13, 2015

Continuous Deployment Using Jenkins, ANT and GitHub for IBM Integration Bus

In my earlier post we dealt with having to use Jenkins, ANT and SVN for Continuous Integration for IBM Integration Bus. In this post lets take it forward and do Continuous Deployment across different environment. Just for some change I decided to use GitHub as the source repository instead of SVN.

So with Jenkins already running we need to add the plugin for GitHub and also need to setup the security. To do that select 'Manage Jenkins' on the left of the screen to open the panel -

Click on the 'Manage Plugins' link and search for 'promoted plugin' with the 'available' highlighted and select 'Install without restart'

Next move to have the security setup. For this click on the 'Manage Jenkins' on the left of the screen as in the first image and click the 'Setup Security' blue button.Setup the security with 'Jenkins' own user database' and 'Allow users to sign up' selected.

Next up set the users that we are going to use for this. I have created the user 'admin' as the admin user for Jenkins and 'intuser' is the developer role to deploy the code to INT, 'testuser' will approve the deployment to TEST and mark it QA Build. 'produser' will approve the deployment to PROD after it has been set to 'GA Release'

Click on 'Apply' and save it by clicking on 'Save'. Next up is to create the users that we have mentioned in the user. Click on the 'Create an account' to create the users.
For simplicity sake I have kept the details simple just to the user id. Create the other users similar to this. 
Now that all the users are created login using user 'intuser' and lets work through the process to deploy the code across different environment with process approval. In this case I have the code in a GitHub repository and will pull the code to a local workspace and build it and deploy to the IIB runtime.

Before we start building the job in Jenkins, lets create the build file that we are going to use to create the bar file and deploy in INT and when promoted run the script to deploy the bar file to TEST and PROD.

First up is the build file to build the bar file and deploy to INT - 

<?xml version="1.0"?>
<project name="project" default="run">
<target name="run" description="">
<antcall target="mqsideploybar" />
</target>

<!--Target to build the broker archive using mqsipackagebar-->
<target name="mqsicreatebar.buildbar">
<echo message="Building Broker Archive file: ${APP.NAME}-${BUILD.NUMBER}.bar " />
<exec executable="${IIB.CREATEBAR}\mqsipackagebar.bat" spawn="false">
<arg value="-w" />
<arg value="${IIB.WORKSPACE}" />
<arg value="-a" />
<arg value="${BARDIR}\${APP.NAME}-${BUILD.NUMBER}.bar" />
<arg value="-k" />
<arg value="${APP.NAME}" />
</exec>
<echo message="Completed building Broker Archive file - ${APP.NAME}-${BUILD.NUMBER}.bar " />
</target>

<!--Target to deploy the broker archive using mqsideploybar-->
<target name="mqsideploybar" depends="mqsicreatebar.buildbar">
<echo message="Deploying Broker Archive file: ${APP.NAME}-${BUILD.NUMBER}.bar " />
<exec executable="${IIB.DEPLOYBAR}\mqsideployscript.bat" spawn="false">
<arg value="${IIB.RUNTIME}" />
<arg value="-e" />
<arg value="${IIB.EG}" />
<arg value="-a" />
<arg value="${BARDIR}\${APP.NAME}-${BUILD.NUMBER}.bar" />
</exec>
<echo message="Completed building Broker Archive file - ${APP.NAME}-${BUILD.NUMBER}.bar " />
</target>
</project>

I have parameterized the build file to accept - 
${IIB.CREATEBAR} - The application name we are building.
${BUILD.NUMBER} - The build number-the build number of the job.
${BARDIR} - The location of the bar file after it has been packaged.
${IIB.RUNTIME} - The IIB Runtime to deploy the bar file to.
${IIB.EG} - The IIB Execution Group to deploy the bar file to.
${IIB.CREATEBAR} - The location of IIB's mqsipackagebar.bat file location.
${IIB.DEPLOYBAR} - The location of IIB's mqsideployscript.bat file location.
The last two properties are the same for IIB10 but anyone using IIB9 and before it would be different.

Moving on to the the build file to promote the bar file to TEST and PROD - 
<?xml version="1.0"?>
<project name="project" default="run">
<target name="run" description="">
<antcall target="mqsideploybar" />
</target>

<!--Target to deploy the broker archive using mqsideploybar-->
<target name="mqsideploybar" >
<echo message="Deploying Broker Archive file: ${APP.NAME}-${PROMOTED.NUMBER}.bar " />
<exec executable="${IIB.DEPLOYBAR}\mqsideployscript.bat" spawn="false">
<arg value="${IIB.RUNTIME}" />
<arg value="-e" />
<arg value="${IIB.EG}" />
<arg value="-a" />
<arg value="${BARDIR}\${APP.NAME}-${PROMOTED.NUMBER}.bar" />
</exec>
<echo message="Completed building Broker Archive file - ${APP.NAME}-${PROMOTED.NUMBER}.bar " />
</target>
</project>

Note that most of the properties for this script remains the same except that PROMOTED.NUMBER takes the position of BUILD.NUMBER.

Create a new job in Jenkins logged in with user intuser -

In this instance I am creating the project 'MFA_AggregationStockQuote_GitHub' as a Freestyle project and click 'OK'. The build file needs 3 properties that we are going to pass on in here. They are - 
IIB.RUNTIME - IIB.INT
IIB.EG - default
APP.NAME - MFA_AggregateStockQuote
Specify the location of the project. In this case we are using GitHub as the repository. Jenkins GitHub plugin allows it to retrieve the files to the local workspace. For simplicity sake I am getting the full repository that includes the sub flow projects I will need. 
Scroll down to the build section and specify the build.xml to push the bar file to the INT environment in this case IIB.INT. Also specify the properties that are needed in the build file as shown.
Now that we have configured the build file to push the bar file to INT environment, we would like to push that bar file to TEST environment if the job is successful. To do this search for the term 'Promote builds when' on the same page and select the check box. Name the promotion process which will be helpful to indicate that it is to be promoted to TEST-in this case 'MFA_AggregationStockQuote_GitHub-ToTEST'. Setup the approvers, in this case it is going to be 'testuser'. Setup the parameters for deployment to TEST i.e. IIB.RUNTIME - IIB.TEST and IIB.EG-default . Enter the ANT script to promote the bar file to TEST and specify the parameters.

Next up, add another step to deploy the bar file to PROD after it has been successfully deployed to TEST. In this case the job will become active after the deployment to INT is successful and promotion to TEST has been done. The job details remain the same as TEST promotion except that the IIB runtime we are changing to IIB.PROD. Also not that the promotion to PROD is reliant on manual approval as well as the promotion to TEST being a success.
Save the job and lets run the build as intuser to initiate the deployment to INT environment. Click on the 'Build with Parameters' link on the left. Make sure that the parameters are as we envisioned and click on 'Build'

This will start the build and the progress bar would be visible in the Build History as shown. 
Click on the date time on the progress bar and then click on the 'Console Output' link on left to view how it is progressing. 
In the end the build was successful and it was deployed to the IIB.INT to execution group default.
A confirmation of the same cane be viewed in here.
 Click on the Promotion Status and this will present the status of the promotion.

Before we move on further click on the workspace link on the left and it will show you the artefacts that have been used to create the bar file - 

Now log off as the user intuser and login as user testuser and click on the job 'MFA_AggregationStockQuote_GitHub'. Click on the Promotion Status and it will show you if any of the builds have been done for the mentioned job as in screen below.
Click on the build number on the left in this case '#8' and click on the Promotion Status. Scroll down to note that this build is now available for TEST deployment because the INT build succeeded and manual approval is requested which we do by clicking on the 'Approve' button. Confirm the parameters before clicking the 'Approve' button.
This will start the promotion to TEST environment and a link will appear to show the log info for the progress. Click on the link to check the console output.
The console output shows that the promotion to TEST was a success and the clarification can be noted from the messages.
Click on the build number and the promotion status and you will notice the update. Now the promotion to TEST job has been updated to show when the last promotion was done and a Silver start appears next to the build number to indicate the success.
Confirmation of the successful deployment of the bar file to IIB.TEST
Next up log off as user testuser and login as the user produser and click on the job and next the build number. The 'Approve button is available to be clicked to deploy the bar file to PROD environment as the TEST promotion was successful and we are going to manually approve the promotion. Click on the Approve button and immediately a link will appear to show the progress.
Click on the link to check the progress.
It will show that the job has been successful and the promotion number will be adjacent.
Click on the job number and now we have the gold star beside the silver star to indicate that the promotion to PROD has been successful. The permalinks show the time when it was done.
Confirmation of the successful promotion to PROD.

















6 comments:

Unknown said...

Hello Godfrey's,

Both in ant and Jenkins "BUILD SUCCESSFUL" msg appears in last but my bar file is not generated. Not sure what is the problem. and also what i need to change if my target IIB is on different machine.

Godfrey's Almanac said...

Shashi,

Apologies for this late response. I did not get an alert when you posted this comment.

In the 'Invoke ANT' section for the 'Targets' give the option '-v', this will generate a verbose output and you might get the actual error that is causing the problem. It has been detailed in my earlier post - http://godfreym.blogspot.com/2015/11/continuous-deployment-for-ibm.html?_sm_au_=iVVvSJrPVJ4Z2276

If you want to change the target to a different machine then you will have to change the ant script for target to include the following -
'-i ipAddress -p port -q qMgr' : hostname, port and queue manager of a remote broker

Hope this helps.

Godfrey

Debjit said...

Hello Godfrey,

In my case the build of Bar file fails and shows a relevant BIPS error code, but the Jenkins log in the Console displays it as Success. So does selecting the option '-v' under 'Invoke ANT' section, will take care of displaying the result as an Error instead of Success.

Thanks,
Debjit

Godfrey's Almanac said...

Debjit,

The -v options gives a verbose output but to display error you may have to change the Ant script to reflect the error.

The fail tag for a job can possibly do that.

Godfrey

SunnG said...

Hello Godfrey,
In my jenkin test it says its deployed to server,but when i check my server its not deployed.

[exec] Successfully Deployed the bar files to -"Server"

Thanks,
Sunny

Godfrey's Almanac said...

Can you share the full trace?