Contents


Automate server push with the Bluemix DevOps delivery pipeline

Configure and automate server directory push in Bluemix

Comments

This tutorial demonstrates how easily you can automate server directory push using WebSphere® Liberty, a fast, easy-to-use Java™ EE application server, and IBM Bluemix DevOps Services. With the Bluemix DevOps Services Build & Deploy feature, you can configure jobs that simultaneously execute commands from Maven, Cloud Foundry, and UNIX to automate server directory push in Bluemix.

What you'll need

This tutorial introduces an easy way to automate your application delivery pipeline using your Eclipse IDE, DevOps Services, and the WebSphere Liberty Java EE application server. To set up the demo app on Bluemix and in your local environment, you'll need the following:

  1. Bluemix account; if you are already registered, you can log in directly to IBM DevOps Services
  2. Eclipse IDE and the Maven plugin for Eclipse
  3. EGit, an Eclipse plugin for Git

Note that Eclipse, Maven, and EGit are optional; you'll only need them if you want to set up and run the demo app in your local environment.

About the demo project

We developed the demo application with Eclipse and Maven on a Linux workstation. We then used EGit to clone a separate Git project in our local development environment. Since this tutorial is about automating server directory push, we won't focus on the demo app. Download the source code and run the app using the buttons below.

Run the appGet the code

The demo app uses a Java servlet to interact with JavaServer Pages. Note the dependency on the javax.servlet API in the Maven POM below.

	<project xmlns="http://maven.apache.org/POM/4.0.0" 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 	http://maven.apache.org/maven-		v4_0_0.xsd">
		<modelVersion>4.0.0</modelVersion>
		<groupId>com.ibm.bluemix.serverpackageautomation</groupId>
  	  <artifactId>testserverpackage</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testserverpackage Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.1.0</version>
		    </dependency>
  	</dependencies>
  <build>
    <finalName>testserverpackage</finalName>
  </build>
	</project>

Step 1. Create a Git project in the DevOps console

Assuming you have built your application in Eclipse with Maven, your first step is to create Git project using Bluemix DevOps Services. You will push your local project in Eclipse in this Git project and deploy it using the Build & Deploy feature.

  1. Open the Bluemix DevOps Services console and choose Create a Project.
  2. Name the project (for example: TestServerPackageAutomation). Image shows naming project step
    Image shows naming project step
  3. Select Create a new repository, then Create a Git repo on Bluemix. Image shows creating Git repo step
    Image shows creating Git repo step
  4. Configure the project as a private project to be deployed to the Bluemix cloud (select all boxes in this panel, as shown). Image shows configuring the project
    Image shows configuring the project
  5. Fill in the required region, organization, and space for deployment in Bluemix. Image shows filling in project details
    Image shows filling in project details

Step 2. Connect your local repo to Bluemix

Next, you'll connect Bluemix DevOps Services to your local Git repository:

  1. From the DevOps Services console, select the demo project: TestServerPackageAutomation. Copy the project's Git URL from the overview page. Image shows copying Git project URL
    Image shows copying Git project URL
  2. Open your Eclipse IDE and right-click the Git Repositories view. Select Paste Repository Path or URI. Image shows adding URL to local repo
    Image shows adding URL to local repo
  3. Input both the URL from Bluemix and your local directory path, then click Next. Image shows entering repo URLs
    Image shows entering repo URLs
    Image shows entering directory path                             for  local environment
    Image shows entering directory path for local environment
  4. When the project clone is complete, you will see the Bluemix project in your Git repository view. Image shows Bluemix project in                              local Git repository view
    Image shows Bluemix project in local Git repository view

Step 3. Commit and push the project

Now commit and push the project from your local environment to Bluemix:

  1. In Eclipse, open Project Explorer and right-click on the project. Image shows opening project in explorer
    Image shows opening project in explorer
  2. Select Team > Share Project, then choose Git as your repository and click Next. Image shows selecting Git
    Image shows selecting Git
  3. Select your project, TestServerPackageAutomation, and click Next. Image shows selecting project
    Image shows selecting project
  4. Right-click the project in Project Explorer, then select Team > Add to Index. Image shows adding project to Bluemix
    Image shows adding project to Bluemix
  5. Right-click on the project in Project Explorer and select Team > Commit. Image shows committing project to Bluemix
    Image shows committing project to Bluemix
  6. Provide a descriptive comment and click Commit and Push. Image shows describing project
    Image shows describing project
  7. Destination Git Repository is automatically selected. Click Commit. Image shows committing project
    Image shows committing project
  8. Select the source reference and destination and click Add Spec, then click Next. Image shows adding project's source reference and                             destination
    Image shows adding project's source reference and destination

On successful push, you'll see the success message.

Figure 1. Success!
Image shows success screen
Image shows success screen

You should now see the project hosted on IBM Bluemix DevOps.

Image shows project on Bluemix
Image shows project on Bluemix

Step 4. Configure the server

Next, you'll set up a server config folder in your Git repository. The defaultServer folder will contain your server.xml configuration file, as well as the WAR file generated for every application build and pushed to Bluemix:

  1. Make a local copy of the server.xml file configured for the demo app.
    	<server description="new server">
    
        		<!-- Enable features from Kaustubh-->
        		<featureManager>
            		<feature>jsp-2.2</feature>
            		<feature>localConnector-1.0</feature>
        		</featureManager>
    
        		<!-- To access this server from a remote client add a host attribute to the following 			element, e.g. host="*" -->
    <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
    <webContainer deferServletLoad="false"/>
    
    <applicationMonitor updateTrigger="mbean"/>
    
    <webApplication id="testserverpackage" location="testserverpackage.war" name="testserverpackage" type="war"/>	
    	</server>
  2. Create a folder called defaultServer in your local Git repository. Image shows creating defaultServer folder
    Image shows creating defaultServer folder
  3. Copy your project's server.xml file, with your server configurations, to the new folder. Image shows adding server.xml
    Image shows adding server.xml
  4. From the Git command line in your local environment, push the folder to Bluemix. Just input the following commands in sequence.
    git add defaultServer
    git add defaultServer/*
    git commit
    git push origin master

    You should see the following output after your successful push.

    Image shows successful output
    Image shows successful output

    You can also confirm that the defaultServer folder resides on Bluemix.

    Image shows confirmation of defaultServer folder on Bluemix
    Image shows confirmation of defaultServer folder on Bluemix

Step 5. Build the application

Your application and its server configuration are now pushed in a Git repository on Bluemix. Next, you'll use the Bluemix DevOps Services Build & Deploy feature to automate the delivery pipeline:

  1. In your Bluemix DevOps Services console, select Build & Deploy, then create a new stage for the build operation. Enter the project URL, input type, and branch. Image shows configure stage
    Image shows configure stage
  2. Next, oonfigure the build by selecting the Jobs tab. Under Builder Type, enter Maven. Image shows configuring build
    Image shows configuring build
  3. Configure the Build Shell. Image shows Build Shell configuration
    Image shows Build Shell configuration

The Build Shell command does the following:

  1. Creates a new directory, apps, in the defaultServer directory.
    mkdir -p defaultServer/apps
  2. Changes the directory to logtest and does a Maven package.
    cd testserverpackag
    	mvn -B package -X -Dmaven.test.skip
  3. Copies the WAR file generated (in the target directory) to the defaultServer/apps folder.
    cp target/*.war ../defaultServer/apps/

Step 6. Run and test the build stage

Before you configure the deploy stage, run and test the build stage you've just configured:

  1. From the DevOps Services Pipeline, run the stage once. Image shows running the stage
    Image shows running the stage
  2. Select View logs and history. Image shows viewing logs and history
    Image shows viewing logs and history
  3. Select the Artifact tab. You should see the application's WAR file copied in the DevOps Services build archive directory under Apps. Image shows verifying WAR file
    Image shows verifying WAR file

Step 7. Configure the deploy stage

Now complete the configuration to deploy the application in Bluemix:

  1. Create a stage with the input type of Build Artifact. Use the same stage and job configurations used for the previous build. Image shows creating  Build Artifcat stage
    Image shows creating Build Artifcat stage
  2. Under this stage, create a new deploy job and configure it as shown. Image shows creating deploy job
    Image shows creating deploy job

    Use the following CFI command to push the application to Bluemix: cf push "${CF_APP}".

  3. When the build and deploy stages are configured properly, they should appear in the DevOps pipeline. Image shows pipeline stages
    Image shows pipeline stages

Step 7. Test it

Make sure you've configured the build stage with the instruction "Automatically execute jobs when a change is pushed to Git," then try pushing in some code changes. The Build & Deploy should start automatically.

Conclusion

In this tutorial, you've learned how to use the Bluemix DevOps Services Build & Deploy feature to configure and automate your application delivery pipeline. For this application example, you simultaneously executed Maven, Cloud Foundry, and UNIX commands in an automated build cycle. You can extend what you've learned here to integrate libraries that are not available in the Maven repository into your next build.


Downloadable resources


Related topics


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=DevOps
ArticleID=1029193
ArticleTitle=Automate server push with the Bluemix DevOps delivery pipeline
publish-date=04052016