Bluemix Devops Services Delivery Pipeline
Bluemix DevOps Services has a delivery pipeline that allows you to build, test, and deploy your web application.
In this tutorial you will learn to set-up a delivery pipeline by creating a build stage, a test stage, and a deploy stage. The build stage will use Gradle. The test stage will use JUnit through Gradle. The deploy stage will use the cf tool.
Prerequisite:
You are required to do the Creating a Web Application using Gradle Tutorial.
- The sample code used in the current tutorial is based from the sample code used in Creating a Web Application using Gradle Tutorial.
You are not required (but recommended) to do the Bluemix Basics Tutorial.
- However, ensure that you have a Bluemix account.
- Your account should have the space
devunder the regionUS-South. The creation of the spacedevis discussed in Bluemix Basics Tutorial.You are not required (but recommended) to do the Bluemix DevOps Services Basics Tutorial.
- However, ensure that you have a Bluemix DevOps Services account.
You are not required (but recommended) to do the GitHub Basics Tutorial.
- However, ensure that you have a GitHub account.
Copy a GitHub Repository
Open a web browser tab and login to GitHub. In this tutorial, we will refer to this browser tab as
GITHUB TAB.Using the same web browser tab (
GITHUB TAB), go to the GitHub repositoryhttps://github.com/pong-pantola/devops-delivery-pipeline.Fork the repository by clicking the
Forkbutton.Verify that you have successfully forked the repository by checking its name:
Name of Repository:
<username>/devops-delivery-pipelineThe repository contains the following.
devops-delivery-pipeline/ | |----build.gradle | |----src/ | |----main/ | | | |----java/net/tutorial/ | | | | | |----Math.java | | |----Calculator.java | | | |----resources/ | | | | | |----log4j.properties | | | |----webapp/ | | | |----calculator.jsp | |----test/ | |----java/net/tutorial/ | |----MyTest.java |----TestRunner.javaThe subdirectories and files are exactly the same as the one you used and created in Creating a Web Application using Gradle Tutorial.
Create a Bluemix DevOps Project based on the GitHub Repository
Open another web browser tab and login to Bluemix DevOps.
Click
CREATE PROJECT.Name your project
devops-delivery-pipeline.Click
Link to an existing GitHub repository.If this is the first time you will link a Bluemix DevOps project to a GitHub repository, you will be asked to authorize your Bluemix DevOps account to access your GitHub account. Proceed with confirming access.
Select the repository
<username>/devops-delivery-pipelineEnsure the following options are chosen:
Private Project checked Add features for Scrum development checked Make this a Bluemix Project checked Region IBM Bluemix US South Organization you may leave the default selection Space dev Click the
CREATEbutton. Wait for your project to be created.Click the
EDIT CODEbutton. You will be redirected to Bluemix DevOps' editor. In this tutorial, we will refer to this browser tab asDEVOPS-EDITOR TAB.The editor shows the working directory (and not the GitHub repository you forked earlier). The working directory is very similar to a local directory in your hard drive as discussed in the GitHub Basics Tutorial. In fact, when you chose to link the existing
<username>/devops-delivery-pipelineremote repository in an earlier step, you basically instructed Bluemix DevOps to clone the said remote repository to the working directory. This is very similar to cloning the remote repository to a local repository (i.e., the one in a hard drive).However, notice that there are additional files/subdirectories (e.g.,
.cfignoreandlaunchConfigurations) that were added in the working directory. These were added automatically when the Bluemix DevOps project was created. To sync the working directory with the GitHub repository<username>/devops-delivery-pipeline, these files/directories need to be pushed to the GitHub remote repository.On the
DEVOPS-EDITOR TAB: Click (open in another browser tab) theGit Repositoryicon found on the left side of the screen. We will refer to this browser tab asDEVOPS-GIT TAB.On the
DEVOPS-GIT TAB: On theWorking Directorysection (right side of the page) Set the following values:Select All checked Commit message files created when Bluemix DevOps project was created On the
DEVOPS-GIT TAB: Click theCommitbutton.On the
DEVOPS-GIT TAB: Click thePushbutton.Your working directory and GitHub repository are now synced.
On the
GITHUB TAB: Refresh the page and verify that.cfignoreandlaunchConfigurationsare added.You are now ready to create the delivery pipeline (i.e., build stage, test stage, deploy stage).
On the
DEVOPS-GIT TAB: Click (open in another browser tab) theBUILD & DEPLOYbutton. We will refer to this browser tab asDEVOPS-DELIVERY-PIPELINE TAB.
Create a Build Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theADD STAGEbutton. Change the stage nameMyStagetoBuild Stage.On the
DEVOPS-DELIVERY-PIPELINE TAB: On theINPUTtab, set the following values:Input Type SCM Repository Git URL https://github.com/ /devops-delivery-pipeline.git Branch master Stage Trigger Run jobs whenever a change is pushed to Git On the
DEVOPS-DELIVERY-PIPELINE TAB: On theJOBStab, click theADD JOBlink and selectBuild. Change the job nameBuildtoGradle Assemble. Set the following values:Builder Type Gradle Build Shell Command #!/bin/bashgradle assembleStop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theSAVEbutton.
Create a Test Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theADD STAGEbutton. Change the stage nameMyStagetoTest Stage.On the
DEVOPS-DELIVERY-PIPELINE TAB: On theINPUTtab, set the following values:Input Type Build Artifacts Stage Build Stage Job Gradle Assemble Stage Trigger Run jobs when the previous stage is completed On the
DEVOPS-DELIVERY-PIPELINE TAB: On theJOBStab, click theADD JOBlink and selectTest. Change the job nameTesttoJUnit Test through Gradle. Set the following values:Tester Type Simple Test Command #!/bin/bashgradle testStop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theSAVEbutton.
Create a Deploy Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theADD STAGEbutton. Change the stage nameMyStagetoDev Deploy Stage.Unlike the build and test stages which are named
Build StageandTest Stage, respectively, the name of the deploy stage you are about to create isDev Deploy Stageto denote that that the application will be deployed in thedevspace of your Bluemix account. Another deploy stage will be created later.On the
DEVOPS-DELIVERY-PIPELINE TAB: On theINPUTtab, set the following values:Input Type Build Artifacts Stage Build Stage Job Gradle Assemble Stage Trigger Run jobs when the previous stage is completed On the
DEVOPS-DELIVERY-PIPELINE TAB: On theJOBStab, click theADD JOBlink and selectDeploy. Change the job nameDeploytoCloud Foundry Push to Dev Space. Set the following values:Deployer Type Cloud Foundry Target IBM Bluemix US South - https://api.ng.bluemix.net Organization you may leave the default selection Space dev Application Name blank Deploy Script #!/bin/bashcf push calculator-<your_name> -m 256M -p build/libs/calcuapp.warStop running this stage if this job fails checked IMPORTANT: In the
cf pushcommand, make sure to change<your_name>to your name.On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theSAVEbutton.You have created a delivery pipeline.
Deploy the Application through the Delivery Pipeline
On the
DEVOPS-DELIVERY-PIPELINE TAB: Click (open in another browser tab) theView logs and historylink of theBuild Stage. We will refer to this browser tab asDEVOPS-BUILD-STAGE-LOGS TAB.On the
DEVOPS-DELIVERY-PIPELINE TAB: Click (open in another browser tab) theView logs and historylink of theTest Stage. We will refer to this browser tab asDEVOPS-TEST-STAGE-LOGS TAB.On the
DEVOPS-DELIVERY-PIPELINE TAB: Click (open in another browser tab) theView logs and historylink of theDev Deploy Stage. We will refer to this browser tab asDEVOPS-DEV-DEPLOY-STAGE-LOGS TAB.The
DEVOPS-BUILD-STAGE-LOGS TAB,DEVOPS-TEST-STAGE-LOGS TAB,DEVOPS-DEV-DEPLOY-STAGE-LOGS TABwill allow you to monitor the status of the delivery pipeline in each stage.Recall that in the Creating a Web Application using Gradle Tutorial the following commands are used:
Command Purpose gradle assemblebuild calcuapp.wargradle testrun the JUnit test cf pushdeploy the web application in Bluemix These three commands are exactly the same commands that the three stages will do.
On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theRun Stageicon of theBuild Stage.Notice that the status of the
Build Stagechanges toSTAGE RUNNING.Once the status of
Build Stagechanges toSTAGE PASSED, theTest Stagewill automatically start.Similarly, when the status of
Test Stagechanges toSTAGE PASSED, theDev Deploy Stagewill automatically start.Wait for the status of the
Dev Deploy Stageto change toSTAGE PASSED.You may view the
DEVOPS-BUILD-STAGE-LOGS TAB,DEVOPS-TEST-STAGE-LOGS TAB,DEVOPS-DEV-DEPLOY-STAGE-LOGS TABto see the logs related to the execution of the three stages.Open another web browser tab. We will refer to this browser tab as
CALCULATOR-APP TAB.On the
CALCULATOR-APP TAB: Go tohttp://calculator-<your_name>.mybluemix.net/calculator.jsp.Output:
5 + 9 = 14 8 - 2 = 6 4 x 7 = 28
Automatically start the Delivery Pipeline
In the previous steps, you manually started the delivery pipeline by clicking the Run Stage icon of the Build Stage.
Since the Build Stage is configured to Run jobs whenever a change is pushed to Git, the delivery pipeline can be started whenever changes occur in the GitHub repository.
On the
GITHUB TAB: Open the filesrc/main/webapp/calculator.jspfor editing.On the
GITHUB TAB: Add the following lines at the end just before the</body>tag:<%="2 + 2 = " + m.add(2, 2)%> <br>On the
GITHUB TAB: Click theCommit changesbutton.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TABand verify that theBuild Stageautomatically started due to the changes made in the GitHub repository.Wait until the three stages are complete.
On the
CALCULATOR-APP TAB: Refresh the page to see the changes made in the calculator application.Output:
5 + 9 = 14 8 - 2 = 6 4 x 7 = 28 2 + 2 = 4As expected,
2 + 2 = 4is included in the output.Let's modify again the file
src/main/webapp/calculator.jspbut this time using the Bluemix DevOps editor and see if the delivery pipeline is automatically triggered.On the
DEVOPS-EDITOR TAB: Open the filesrc/main/webapp/calculator.jsp.Notice that the lines you added in the
calculator.jsp(i.e.,<%="2 + 2 = " + m.add(2, 2)%>and<br>) in your GitHub repository do not appear incalculator.jspof your working directory.You need first to sync the working directory in your Bluemix DevOps project before you start editing another file.
On the
DEVOPS-GIT TAB: Refresh the page.On the
DEVOPS-GIT TAB: Notice that there is anIncomingchange due to the modification you did oncalculator.jspin GitHub. Click theSyncbutton to update the copy ofcalculator.jspin the working directory in your Bluemix DevOps project.On the
DEVOPS-EDITOR TAB: Refresh the page and reopen the filesrc/main/webapp/calculator.jsp. Notice that the following lines now exist:<%="2 + 2 = " + m.add(2, 2)%> <br>On the
DEVOPS-EDITOR TAB: Add the following lines at the end just before the</body>tag:<%="3 - 3 = " + m.sub(3, 3)%> <br>On the
DEVOPS-EDITOR TAB: Make sure to save the changes made.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB.Notice that the
Build Stagedid not start automatically. You only changed thecalculator.jspthat is in the working directory and not the one in the GitHub repository. You need to push the changes made in the working directory to the GitHub repository for theBuild Stageto start.On the
DEVOPS-GIT TAB: Refresh the page.On the
DEVOPS-GIT TAB: Set the following values:Select All checked Commit message added another computation On the
DEVOPS-GIT TAB: Click theCommitbutton.On the
DEVOPS-GIT TAB: Click thePushbutton.Your GitHub repository is now updated with the new version of
calculator.jsp.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TABand verify that theBuild Stageautomatically started due to the changes made in the GitHub repository.
See the Effect if an Error is encountered in the Delivery Piipeline
You will intentionally introduce errors in src/main/java/net/tutorial/Math.java so that you can verify if the Test Stage will detect the errors.
On the
GITHUB TAB: Open the filesrc/main/java/net/tutorial/Math.javafor editing.On the
GITHUB TAB: Change the methodaddto the following:public int add(int a, int b){ return a-b; }Since
a+bis changed toa-b, we expect an error to be reported related to theaddmethod.This error is discussed in detail in the JUnit Basics Tutorial and revisited in Gradle's Unit Testing Tutorial.
On the
GITHUB TAB: Change the methodmultiplyto the following:public int multiply(int a, int b){ delay(); return a*b; }Since
delay()is added, we expect thatmultiplymethod will execute for at least 3 secs.. This will cause a timeout error.This error is also discussed in detail in the JUnit Basics Tutorial and revisited in Gradle's Unit Testing Tutorial.
On the
GITHUB TAB: Click theCommit changesbutton.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB.As expected, the
Build Stagestarted automatically.After the
Build Stageis complete, theTest Stagewill start as well. Due to the errors you introduced in the previous steps, the status of theTest StagebecomesSTAGE FAILED.On the
DEVOPS-TEST-STAGE-LOGS TAB: View the logs to verify that bothaddandmultiplymethods encounter problems.On the
GITHUB TAB: Open again the filesrc/main/java/net/tutorial/Math.javafor editing. Correct the errors you introduced earlier (i.e., bring backa+bin theaddmethod and remove thedelay()in themultiplymethod). Don't forget to click theCommit changesbutton.On the
DEVOPS-DELIVERY-PIPELINE TAB: Ensure that all the stages are executed successfully.
Create another Deploy Stage
The Dev Deploy Stage created earlier deploys the web application in the dev space in your Bluemix account.
You will create another deploy stage called Prod Deploy Stage which will redeploy the same application in the prod space in your Bluemix account.
Having separate deploy stages for development and production is essential to ensure that features/functionalities that are added to a web application is verified first in the dev space. Once the features/functionalities are verified to be working properly, this is the only time the updated web application is redeployed to the prod space through the Prod Deploy Stage.
Make sure that you have a
prodspace under the regionUS-Southin your Bluemix account.If you don't have a
prodspace, you may use the Bluemix Basics Tutorial as a guide in creating a space.On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theADD STAGEbutton. Change the stage nameMyStagetoProd Deploy Stage.On the
DEVOPS-DELIVERY-PIPELINE TAB: On theINPUTtab, set the following values:Input Type Build Artifacts Stage Build Stage Job Gradle Assemble Stage Trigger Run jobs only when this stage is run manually It should be noted that the Stage Trigger for this stage is
Run jobs only when this stage is run manually. This is different from theDev Deploy Stagethat uses the Stage TriggerRun jobs when the previous stage is completed.Unlike the web application in the
devspace, the web application deployed in theprodspace should be free from errors. If you use the Stage TriggerRun jobs when the previous stage is completed, it is possible that an application developer may push changes to the GitHub repository which will eventually trigger theProd Deploy Stageto run even if the changes made by the developer are unverified.On the
DEVOPS-DELIVERY-PIPELINE TAB: On theJOBStab, click theADD JOBlink and selectDeploy. Change the job nameDeploytoCloud Foundry Push to Prod Space. Set the following values:Deployer Type Cloud Foundry Target IBM Bluemix US South - https://api.ng.bluemix.net Organization you may leave the default selection Space prod Application Name blank Deploy Script #!/bin/bashcf push calculator-prod-<your_name> -m 256M -p build/libs/calcuapp.warStop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theSAVEbutton.You have completed the
Prod Deploy Stage. You can now test the Stage Trigger of this stage.On the
GITHUB TAB: Open the filesrc/main/webapp/calculator.jspfor editing.On the
GITHUB TAB: Add the following lines at the end just before the</body>tag:<%="4 x 4 = " + m.add(4, 4)%> <br>On the
GITHUB TAB: Click theCommit changesbutton.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TABand verify that theBuild Stageis triggered automatically, followed by theTest Stage, and followed by theDev Deploy Stage. Wait for the first three stages to completely execute.Notice that the
Prod Deploy Stagedoes not start automatically after theDev Deploy Stageis complete. You need to manually start theProd Deploy Stage.On the
DEVOPS-DELIVERY-PIPELINE TAB: Click theRun Stageicon of theProd Deploy Stage.Wait for this stage to be completed.
Open another web browser tab. We will refer to this browser tab as
CALCULATOR-PROD-APP TAB.On the
CALCULATOR-PROD-APP TAB: Go tohttp://calculator-prod-<your_name>.mybluemix.net/calculator.jsp.Output:
5 + 9 = 14 8 - 2 = 6 4 x 7 = 28 2 + 2 = 4 3 - 3 = 0 4 x 4 = 16Note that what you have viewed is the production version of the calculator application (
http://calculator-prod-<your_name>.mybluemix.net/calculator.jsp)The development version of the application is accessible through
http://calculator-<your_name>.mybluemix.net/calculator.jsp.To make sure that the working directory of your Bluemix DevOps project is in sync with your GitHub repository, you will sync again the changes you made in your GitHub repository.
On the
DEVOPS-GIT TAB: Refresh the page.On the
DEVOPS-GIT TAB: Notice that there is anIncomingchange due to the modification you did onMath.javaandcalculator.jspin GitHub. Click theSyncbutton to update the copy ofMath.javaandcalculator.jspin the working directory in your Bluemix DevOps project.
Delete the Bluemix Applications
Delete the two applications (i.e., the one deployed in
devspace and the other one deployed inprodspace) in your Bluemix account.This will free up some resources which is essential to accommodate new applications and services you want to deploy in the future.
You may retain the Bluemix DevOps project
devops-delivery-pipelineand your/devops-delivery-pipeline GitHub repository. The DevOps project and the GitHub repository are needed in the Bluemix DevOps Services Track and Plan Tutorial, DO NOT delete your
You may close all the browser tabs you have opened.
End of Tutorial
Go back to the List of Tutorials.
