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
dev
under the regionUS-South
. The creation of the spacedev
is 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
Fork
button.Verify that you have successfully forked the repository by checking its name:
Name of Repository:
<username>/devops-delivery-pipeline
The 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.java
The 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-pipeline
Ensure 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
CREATE
button. Wait for your project to be created.Click the
EDIT CODE
button. 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-pipeline
remote 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.,
.cfignore
andlaunchConfigurations
) 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 Repository
icon 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 Directory
section (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 theCommit
button.On the
DEVOPS-GIT TAB
: Click thePush
button.Your working directory and GitHub repository are now synced.
On the
GITHUB TAB
: Refresh the page and verify that.cfignore
andlaunchConfigurations
are 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 & DEPLOY
button. We will refer to this browser tab asDEVOPS-DELIVERY-PIPELINE TAB
.
Create a Build Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theADD STAGE
button. Change the stage nameMyStage
toBuild Stage
.On the
DEVOPS-DELIVERY-PIPELINE TAB
: On theINPUT
tab, 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 theJOBS
tab, click theADD JOB
link and selectBuild
. Change the job nameBuild
toGradle Assemble
. Set the following values:Builder Type Gradle Build Shell Command #!/bin/bash
gradle assemble
Stop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theSAVE
button.
Create a Test Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theADD STAGE
button. Change the stage nameMyStage
toTest Stage
.On the
DEVOPS-DELIVERY-PIPELINE TAB
: On theINPUT
tab, 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 theJOBS
tab, click theADD JOB
link and selectTest
. Change the job nameTest
toJUnit Test through Gradle
. Set the following values:Tester Type Simple Test Command #!/bin/bash
gradle test
Stop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theSAVE
button.
Create a Deploy Stage
On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theADD STAGE
button. Change the stage nameMyStage
toDev Deploy Stage
.Unlike the build and test stages which are named
Build Stage
andTest Stage
, respectively, the name of the deploy stage you are about to create isDev Deploy Stage
to denote that that the application will be deployed in thedev
space of your Bluemix account. Another deploy stage will be created later.On the
DEVOPS-DELIVERY-PIPELINE TAB
: On theINPUT
tab, 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 theJOBS
tab, click theADD JOB
link and selectDeploy
. Change the job nameDeploy
toCloud 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/bash
cf push calculator-<your_name> -m 256M -p build/libs/calcuapp.war
Stop running this stage if this job fails checked IMPORTANT: In the
cf push
command, make sure to change<your_name>
to your name.On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theSAVE
button.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 history
link 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 history
link 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 history
link 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 TAB
will 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 assemble
build calcuapp.war
gradle test
run the JUnit test cf push
deploy 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 Stage
icon of theBuild Stage
.Notice that the status of the
Build Stage
changes toSTAGE RUNNING
.Once the status of
Build Stage
changes toSTAGE PASSED
, theTest Stage
will automatically start.Similarly, when the status of
Test Stage
changes toSTAGE PASSED
, theDev Deploy Stage
will automatically start.Wait for the status of the
Dev Deploy Stage
to change toSTAGE PASSED
.You may view the
DEVOPS-BUILD-STAGE-LOGS TAB
,DEVOPS-TEST-STAGE-LOGS TAB
,DEVOPS-DEV-DEPLOY-STAGE-LOGS TAB
to 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.jsp
for 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 changes
button.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB
and verify that theBuild Stage
automatically 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 = 4
As expected,
2 + 2 = 4
is included in the output.Let's modify again the file
src/main/webapp/calculator.jsp
but 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.jsp
of 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 anIncoming
change due to the modification you did oncalculator.jsp
in GitHub. Click theSync
button to update the copy ofcalculator.jsp
in 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 Stage
did not start automatically. You only changed thecalculator.jsp
that 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 Stage
to 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 theCommit
button.On the
DEVOPS-GIT TAB
: Click thePush
button.Your GitHub repository is now updated with the new version of
calculator.jsp
.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB
and verify that theBuild Stage
automatically 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.java
for editing.On the
GITHUB TAB
: Change the methodadd
to the following:public int add(int a, int b){ return a-b; }
Since
a+b
is changed toa-b
, we expect an error to be reported related to theadd
method.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 methodmultiply
to the following:public int multiply(int a, int b){ delay(); return a*b; }
Since
delay()
is added, we expect thatmultiply
method 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 changes
button.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB
.As expected, the
Build Stage
started automatically.After the
Build Stage
is complete, theTest Stage
will start as well. Due to the errors you introduced in the previous steps, the status of theTest Stage
becomesSTAGE FAILED
.On the
DEVOPS-TEST-STAGE-LOGS TAB
: View the logs to verify that bothadd
andmultiply
methods encounter problems.On the
GITHUB TAB
: Open again the filesrc/main/java/net/tutorial/Math.java
for editing. Correct the errors you introduced earlier (i.e., bring backa+b
in theadd
method and remove thedelay()
in themultiply
method). Don't forget to click theCommit changes
button.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
prod
space under the regionUS-South
in your Bluemix account.If you don't have a
prod
space, you may use the Bluemix Basics Tutorial as a guide in creating a space.On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theADD STAGE
button. Change the stage nameMyStage
toProd Deploy Stage
.On the
DEVOPS-DELIVERY-PIPELINE TAB
: On theINPUT
tab, 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 Stage
that uses the Stage TriggerRun jobs when the previous stage is completed
.Unlike the web application in the
dev
space, the web application deployed in theprod
space 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 Stage
to run even if the changes made by the developer are unverified.On the
DEVOPS-DELIVERY-PIPELINE TAB
: On theJOBS
tab, click theADD JOB
link and selectDeploy
. Change the job nameDeploy
toCloud 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/bash
cf push calculator-prod-<your_name> -m 256M -p build/libs/calcuapp.war
Stop running this stage if this job fails checked On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theSAVE
button.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.jsp
for 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 changes
button.Quickly switch to the
DEVOPS-DELIVERY-PIPELINE TAB
and verify that theBuild Stage
is 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 Stage
does not start automatically after theDev Deploy Stage
is complete. You need to manually start theProd Deploy Stage
.On the
DEVOPS-DELIVERY-PIPELINE TAB
: Click theRun Stage
icon 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 = 16
Note 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 anIncoming
change due to the modification you did onMath.java
andcalculator.jsp
in GitHub. Click theSync
button to update the copy ofMath.java
andcalculator.jsp
in the working directory in your Bluemix DevOps project.
Delete the Bluemix Applications
Delete the two applications (i.e., the one deployed in
dev
space and the other one deployed inprod
space) 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-pipeline
and 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.