How to Continuously Deploy Code with CloudBees Jenkins for Pivotal CF

October 22, 2014 Ben Laplanche

featured-jenkins-bluePivotal CF customers can now download and install Jenkins Enterprise by Cloudbees with Pivotal Ops Manager, providing easy configuration with a fully integrated user experience.

Last month, we launched a partnership with CloudBees, the company behind the popular open source Jenkins Continuous Integration tool chain. Continuous integration and delivery are at the heart of the way we make software at Pivotal, and Jenkins makes us agileallowing for quick iterations while delivering high quality software to our customers. This is why Jenkins is one of our favorite CI tools, and it is now available as a turnkey add-on service for Pivotal CF. You can download it from the Pivotal Network.

The Jenkins Enterprise service is deployed via Ops Manager with minimal configuration. Ops Manager simplifies the process of installing and configuring Jenkins, including the setup of master and slave node, registration of a trial licence, setup of additional useful developer plugins, and integration with Cloud Foundry’s User Authorization and Authentication (UAA) service. With single sign on (SSO), developers can also log in with existing credentials.

image02

Jenkins infrastructure can easily be scaled up and down or re-deployed straight from Ops Manager. The flexibility of the Cloud Foundry platform applies to partner services as well.

Integrating with Pivotal Cloud Foundry

The features that I am most proud of put the application developer experience at the centre of the product, ensuring a consistent development, testing, and staging experience.

We mimic the runtime environment for Ruby and NodeJS applications, and we allow you to provision and bind to service instances such as your database. The approach enables integration testing and allows for direct deployment from Jenkins into your chosen Pivotal CF environment.

How Does It Work?

Visit your CloudBees Jenkins installation at http://pivotal-cloudbees.your-cf-installation.com and click on New Item. Then choose the “Build a free-style software project” to get started.

image01

Using an example Ruby and Redis test application from GitHub, you can run the test suite for this application, and provision a Redis instance on your Pivotal CF installation.

Next, create a build step to Execute Shell commands.

image03

Type in the following code.

image00

It is important to understand and walk through this code block, section by section:

Using Buildpacks and Data Services

. cf_buildpack
export REQUIRED_SERVICE_INSTANCES=’p-redis:development:redis’
. test_service_instances
rspec

The first line tells Jenkins to use the same Ruby build pack to run your application during the tests as would be used in the runtime environment, helping to ensure consistency.

The second line exports the data service and plan you would like to use. Here, we are using the `p-redis` product, with the `development` plan and we are going to refer to it as `redis`.

The third line provisions an instance of the Redis development plan to be used during your tests and binds your application to it. The last line runs the Rspec test suite provided in the GitHub repo.

Targeting Your PCF Environment

cf api https://api.your-cf-installation.com --skip-ssl-validation
cf login -u me -p password -o development -s development

The first line targets the Cloud Foundry CLI to your Pivotal CF environment. For example, this is your production application where you wish to deploy your app after a successful test run.

The second line authenticates with your username and password and chooses the development organisation and space.

Pushing Your Application

cf create-service p-redis development redis
cf push redis-example-app —no-start
cf bind-service redis-example-app redis
cf restart redis-example-app

The first line creates a service instance of Redis in your deployment environment, called `redis`.

The second line will push your application with the name `redis-example-app` and does not start it yet.

The third line binds your `redis` instance to your application, and the last line restarts your application so it can utilise this binding information.

Getting Started

That is how easy it is to use Jenkins to pull an application from your GitHub repo, use buildpacks, create test data service instances, log in to your deployment Pivotal CF environment, and push the app live!

You can read the documentation for CloudBees Enterprise Jenkins for Pivotal CF or a more detailed guide on how to test your app and deploy to Pivotal CF.

About the Author

Biography

Previous
Parsing JSON in Objective-C
Parsing JSON in Objective-C

If you have full control of the resulting API endpoints, then it is easy to build or fix the API to your cl...

Next
All Things Pivotal Episode #3 – Comparing Big vs Fast Data
All Things Pivotal Episode #3 – Comparing Big vs Fast Data

In this week's episode, Simon discusses Big vs Fast data and how you might use it, the components involved ...