Contents


Bluemix fundamentals: Set up team collaboration and automatic deployments for your Java app

Introduction to DevOps Services

Comments

Overview

Learn how to create a DevOps Services project where you can store your code in a Git repository and create a Delivery Pipeline that automatically deploys the latest version of your app whenever anyone on your team pushes a change to your Git repository.

This tutorial is part of the "Bluemix fundamentals" tutorial series on developerWorks.

 

What you'll do in this tutorial

Step 1. Prepare your Eclipse workspace

Step 2. Create a DevOps Services project

Step 3. Push code to a Git repository

Step 4. Configure the Delivery Pipeline

Step 5. Trigger the Delivery Pipeline by pushing a change to the Git repository

Step 6. Observe the Delivery Pipeline

What's next?

Let's get started

Previously in "Deploy a sample Java application to the cloud,” you learned how to run, modify, test, and deploy web apps to the cloud using the Java™ language and either the Cloud Foundry command-line interface or the IBM Bluemix Tools for Eclipse. Now that you know how to deploy an app to Bluemix so that anyone on the Internet can access it, you might be wondering what DevOps support is available to make your development and operations processes easy and efficient.

IBM Bluemix DevOps Services is a software as a service (SaaS) on the cloud that supports continuous delivery. With DevOps Services, you can develop, track, plan, and deploy software in one place.

Knowledge that you need for this tutorial

Software that you need for this tutorial

  • A Bluemix account (register for your free trial account or log in to Bluemix if you already have an account).
  • The following software installed on your computer:

Step 1. Prepare your Eclipse workspace

You begin this tutorial by importing a new copy of the sample Java web app to an Eclipse workspace. The code is very similar to the code from the previous tutorial with a few file additions including build.xml, manifest.yml, and Junit jars.

  1. Click this button to download the code for the sample Java web app, javatutorial2.zip:
  2. In a new Eclipse workspace, import the code as an Existing Project. Detailed instructions are in Step 3 of "Deploy a sample Java application to the cloud.”

Step 2. Create a DevOps Services project

In a DevOps Services project, one or more people can build, share, organize, and manage versions of resources to achieve a goal. Typically, that goal is to create an app. In this step, you'll create a DevOps Services project that will contain your Git repository and Delivery Pipeline.

  1. Navigate to DevOps Services.
  2. Log in using your IBM ID (the same ID you use for Bluemix) if you are not already authenticated.
  3. On the MY PROJECTS page, click CREATE PROJECT.
  4. On the Create a project page:
    1. Type a name for your project.
    2. Click Create a new repository.
    3. Click Create a Git repo on Bluemix.
    4. Make sure that the "Add features for Scrum development" box is checked.
    5. Make sure that the "Make this a Bluemix Project" box is checked.
    6. Select the Bluemix Region, Organization, and Space where you want your app to be deployed.
    7. Click CREATE.

A DevOps Services project is now created for you. You can explore your project, invite others to work with you on your project, and update your project’s image and description.

Step 3. Push code to a Git repository

Storing code in source control has a variety of benefits including providing a backup of your code, allowing you to roll back to previous versions, enabling you to view a history of your code to understand why changes were made, and allowing you to easily work with teammates on the same code base.

In this tutorial, you'll store your code in a Git repository hosted on Bluemix. You'll use the EGit Eclipse plug-in to manage your connection to the Git repository. If you prefer, you can use another tool to work with your Git repository like a command line interface or a GUI tool.

Get the Git URL for your repo on DevOps Services

  1. On your project’s page on DevOps Services, click the gear icon in the upper-right to open the project settings.
  2. Copy the Git URL.

Create a local Git repository

  1. In the Package Explorer view in Eclipse, right-click the LaurenLandscapesJava project and select Team > Share Project.
  2. Click Git.
  3. Click Next.
  4. Click Create….
  5. Browse and select the directory where you want your local Git repository to be stored, and click OK.
  6. Click Finish.
  7. In the Configure Git Repository dialog, click Finish.

Add files to source control

Next, you’ll select which files should be tracked in source control and which files should be ignored.

  1. In the Navigator view, right-click the LaurenLandscapesJava project and select Team > Add to Index.
  2. In the Navigator view, right-click the build directory and select Team > Remove from Index.
  3. In the Navigator view, right-click the build directory and select Team > Ignore.

Commit your code to the local Git repository

Now that you have indicated which files should be tracked in source control, you can commit your changes to your local Git repository.

  1. In the Navigator view, right-click the LaurenLandscapesJava project and select Team > Commit….
  2. Enter a commit message and click Commit.

Push code to the DevOps Services Git repository

Next you’ll push your commit to the remote Git repository on DevOps Services.

  1. In the Navigator view, right-click the LaurenLandscapesJava project and select Team > Remote > Push….
  2. In the URI field, paste the DevOps Service Git URL you copied earlier.
  3. In the Authentication section, type your IBM ID and password.
  4. Click Next.
  5. Click Add All Branches Spec.
  6. Click Finish.
  7. When your commit has been successfully pushed, a confirmation dialog will be displayed. Click OK.

Your project code is now stored in the Git repository in your DevOps Services project. If you navigate to DevOps Services and select your project, you'll see a read-only view of the code displayed.

Step 4. Configure the Delivery Pipeline

One of the keys to a successful DevOps approach is having automated builds and deployments. Luckily, DevOps Services has the Delivery Pipeline service you can configure to build, test, and deploy your app to Bluemix through either an automatic or manual trigger.

In Bluemix, organizations and spaces are organizational units in the Cloud Foundry infrastructure that you can use to store and track application resources. An organization contains domains, spaces, and users; a space contains applications and services.

By default, a dev (development) space is created for you when you log in to Bluemix for the first time. For this tutorial, think of the dev space as representing a place for testing code live in a production-quality environment without putting it into actual production. (Some might call this a quality-assurance or test space.) In this step, you’ll create a new space named prod to represent your production space: the place where you keep apps that your end users will use.

You’ll also configure the Delivery Pipeline service to build and deploy your app to both your dev space and prod space in Bluemix whenever you or someone on your team pushes code to your project’s Git repository.

Create a build stage that will build your app

  1. On your project’s page on DevOps Services, click BUILD & DEPLOY in the upper-right corner.
  2. Click ADD STAGE.
  3. Click MyStage at the top of the Stage Configuration dialog box and name your stage by typing Build Stage.
  4. Notice that the Input Type is set to "SCM Repository" by default. This setting means that the input for the stage will be your Git repository.
  5. Notice that "Run jobs whenever a change is pushed to Git" is selected by default. This selection means that whenever you or someone else on your team pushes code to your project's repository, the build stage will automatically be triggered.
  6. Click JOBS to open the Jobs section of the Stage Configuration dialog box.
  7. Click ADD JOB and select Build.
  8. In the Builder Type drop-down list, select Ant. The sample project code includes build.xml that the pipeline will use. (You can explore the contents of build.xml by switching to Eclipse.)
  9. In the Working Directory field, type LaurenLandscapesJava.
  10. Check the box to Enable Test Report.
  11. Notice that the "Stop stage execution on job failure" check box is selected by default. This selection means that if a failure occurs, any jobs further down the pipeline will not run, and the whole stage will be marked as failed.
  12. Click SAVE.

Create a deploy stage that will deploy your app to your dev space in Bluemix

  1. Click ADD STAGE.
  2. Click MyStage at the top of the Stage Configuration dialog box, and name your stage by typing Dev Deployment.
  3. Notice that the Input Type is set to "Build Artifacts." This setting means that build artifacts created in the previous stage will be the input to this stage.
  4. Notice that "Run jobs when the previous stage is completed" is selected by default. This setting configures your pipeline so that whenever someone pushes code to your project's repository, the build step will run, and, if it succeeds, a deployment to the development environment will be kicked off.
  5. Click JOBS to open the Jobs section of the Stage Configuration dialog box.
  6. Click ADD JOB and select Deploy.
  7. Change the Application Name to a name that is unique to your Bluemix dev space.
  8. By default, the deployer uses the instructions in the manifest. The manifest currently sets the host to llljava-${random-word}. You want your app to deploy to a consistent URL where developers on your team can test their code, rather than to a URL that contains a random string of characters.

    So in the Deploy Script section, after cf push "${CF_APP}", add:
    -n whateverYouWantYourUrlToBe

    Note: The URL must be unique across all Bluemix apps, so be creative.
  9. Click SAVE.

Create a prod stage that will deploy your app to your prod space in Bluemix

  1. Click ADD STAGE.
  2. Click MyStage at the top of the Stage Configuration dialog box, and name your stage by typing Prod Deployment.
  3. Notice that the Input Type is set to "Build Artifacts." This setting means that build artifacts created in the Build Stage will be the input to this stage.
  4. Notice that "Run jobs when the previous stage is completed" is selected by default. This setting configures your pipeline so that if the Dev Deployment stage succeeds, this stage will run.
  5. Click JOBS to open the Jobs section of the Stage Configuration dialog box.
  6. Click ADD JOB and select Deploy.
  7. In the Space field, select Create a new space.
  8. In the Enter space name field, type prod, and click CREATE.
  9. Change the Application Name to a name that is unique to your Bluemix prod space.
  10. By default, the deployer uses the instructions in the manifest. You want your app to deploy to a consistent URL where end users can access your app, rather than to a URL that contains a random string of characters.

    So in the Deploy Script section, after cf push "${CF_APP}", add:
    -n whateverYouWantYourUrlToBe

    Note: Remember that the URL must be unique across all Bluemix apps, so be creative.
  11. Click SAVE.

You now have a Delivery Pipeline that will build your app (including running Junit tests), deploy your app to your dev space, and then deploy your app to your prod space.

Step 5. Trigger the Delivery Pipeline by pushing a change to the Git repository

Now that you’ve configured the Delivery Pipeline, it’s time to try it out! One way is to manually trigger the pipeline by clicking the play button in the Build Stage. Another option is to trigger the pipeline by pushing a change to the Git repository, which is what you’ll do in this step.

Make a change to the code

The first thing you need to do is make a change to a file.

  1. In the Navigator view in Eclipse, open WebContent > australia.jsp.
  2. Scroll down the editor until you see:
    <div id="price">120.00</div>
  3. Change the price from 120.00 to 130.00 (demand just went up!).
  4. Save the file.

Commit your code to the local Git repository

Now that you have changed a file, you can commit your change to your local Git repository and push it to the remote Git repository hosted at DevOps Services.

  1. In the Navigator view, right-click the LaurenLandscapesJava project and select Team > Commit….
  2. Type a commit message and click Commit and Push. If prompted for the Destination Git Repository, type the Git Repository URL and your IBM ID and password. Click Next, click Add All Branches Spec., and Finish through the dialogs.
  3. In the Push Results dialog, click OK.

Step 6. Observe the Delivery Pipeline

The change you pushed to the Git repository hosted at DevOps Services in the previous step automatically triggered the Delivery Pipeline. In this step, you’ll explore the results of the pipeline. You can view some of the logs and results while the pipeline is still running. The instructions below assume the pipeline has completed, but feel free to explore the pipeline while it’s running.

  1. On your project’s page on DevOps Services, click BUILD & DEPLOY in the upper-right corner.
  2. In the Build Stage tile, observe that the last Build job succeeded. Click View logs and history.
  3. On the LOGS tab, you can see the output of build.xml being executed. Notice that you can see the results of the war being built and the unit tests being executed.
  4. Click the TESTS tab.
  5. Notice that two tests passed. Click com.ibm.devworks.examples.java.lll.TestWebsiteTitle to see the list of tests included in the file.
  6. Click the ARTIFACTS tab. Observe that the build generated a war file and manifest. These are the artifacts that the deploy stages will use.
  7. Click Back to Pipeline at the top of the page.
  8. In the Dev Deployment tile, observe that the Deploy succeeded. Click View logs and history.
  9. On the LOGS tab, you can see the output of the deployment.
  10. Click Back to Pipeline at the top of the page.
  11. In the Dev Deployment tile, notice that you can click the URL for your running app to view it. You can also view the runtime log, which is helpful when debugging issues.
  12. Explore the Prod Deployment’s logs and running app.

What's next?

In this tutorial, you learned how to use DevOps Services in Bluemix to:

  • Create a project on DevOps Services that hosts a Git repository
  • Push code to the remote Git repository
  • Create a Delivery Pipeline that builds your app, runs unit tests, and deploys the app to multiple stages whenever you or someone on your team pushes code to your project’s repository.

Now, continue learning "Bluemix fundamentals" on developerWorks with this next tutorial. You'll see how to enhance and add functionality to your app via cloud services:

More Bluemix resources

For a steady stream of tutorials and other technical resources to help you learn, develop, and connect with Bluemix, see the Bluemix page on developerWorks.


Downloadable resources


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Cloud computing, Java development, Web development
ArticleID=1015412
ArticleTitle=Bluemix fundamentals: Set up team collaboration and automatic deployments for your Java app
publish-date=10052015