Continuous Delivery for Ruby with CloudBees Jenkins Enterprise

Note: CloudBees Jenkins Platform for PCF is deprecated, and no further development will be made against this tile.

Known limitation

The test_service_instances feature to use Cloud Foundry services bindings in builds has been temporarily disabled (14.11.x and 15.05.x versions). We are working on reintroducing it.

Introduction

This is a guide on how to use CloudBees Jenkins Enterprise for Pivotal Cloud Foundry (PCF) and integrate with your Cloud Foundry installation.

This guide will cover:

  1. Cloning an application from Github
  2. Testing using the Ruby buildpack
  3. Testing against a Redis service instance
  4. Configuring your CF installation
  5. Pushing your application

Getting setup

  1. Log in to Jenkins at http://jenkins-0.your-cf-installation.example.com (or http://pivotal-cloudbees.your-cf-installation.example.com if you are using a backward compatible hostname).
  2. Click New item on the left hand navigation menu.
  3. Choose Build a free-style software project, give it a name, such as redis-test-build, and click ok.

Step1

Clone from Github

We are going to use a provided test application for this demonstration, which is hosted on Github.

  1. Under the Source code management heading, click the Git radio button.
  2. In the path, enter https://github.com/pivotal-cf/cf-redis-example-app/.

Step2

Adding a shell step

The rest of the steps in this guide happen in a shell step.

  1. Under the Build heading, click the Add a build step drop down menu.
  2. Select Execute Shell.

Step3

Buildpacks

In order to run your tests in an environment that mimics the Cloud Foundry runtime environment, you can use the same buildpacks:

  1. In the shell step add . cf_buildpack as the fist line

Note:

  • It is important to add the . fullstop and following space, as the command is executed in a sh shell.

Step4

Test Services

Known limitation: The test_service_instances feature to use Cloud Foundry services bindings in builds has been temporarily disabled (14.11.x and 15.05.x versions). We are working on reintroducing it.

You can create instances of the same services that you use in your development, staging, and production environments to use for your tests.

Our test app uses Redis, so we’ll create a test instance of this for use only in our tests.

  1. In the shell step below the previous line, add export REQUIRED_SERVICE_INSTANCES="p-redis:development:redis"
  2. Followed by . test_service_instances on another line
  3. Finally followed by rspec.

Step5

Cloud Foundry CLI

The CLI is provided for use in shell steps exactly the same as using it from your local machine. Under Build Environment check Set up Cloud Foundry CLI

  • API EndPoint: https://api.your-cf-installation.example.com/
  • Skip ssl Validation: checked if you use a self-signed/untrusted certificate
  • API Credentials: select your PCF/UAA Credentials (CloudFoundry CLI credentials may only be configured at the folder-level, see ‘credentials’ section for more details )
  • Organization: the organization you belong to on PCF
  • Space: the space of your organization in which you would like to deploy the application

Step6

Pushing and binding your application

These steps will create the service, push your application, bind to it and then restart.

  1. Create the redis service with cf create-service p-redis development redis. This command will fail gracefully if the service does already exist.
  2. Push your application and do not start yet: cf push redis-example-app --no-start
  3. Bind your application to the service created in step 1: cf bind-service redis-example-app redis
  4. Restart your application to use the newly created bindings and environment variables: cf restart redis-example-app

Step7

Note: An alternative to steps 2-4 above would be to add your service information into the manifest.yml file in the root of the sample application. This would replace these steps with cf push redis-example-app. For more information about manifests, see the Deploying with Application Manifests topic.

Note: The complete shell step details
. cf_buildpack
export REQUIRED_SERVICE_INSTANCES="p-redis:development:redis”
. test_service_instances
rspec

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

Save & Build

  1. Click save at the bottom of the page.
  2. On the left hand menu, click Build Now. Your new build job will then appear below.

Step8

For more details, click on the icon to the left of the number to see the console output.

You will see output similar to the following:

+ . cf_buildpack
+ set +xe
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
       Running: bundle install --without none --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
       installing your bundle as root will break this application for all non-root
       users on this machine.
       Fetching gem metadata from https://rubygems.org/.........
       Fetching http://github.com/cloudfoundry/cf-app-utils-ruby.git
       Using cf-app-utils 0.3 from http://github.com/cloudfoundry/cf-app-utils-ruby.git (at master)
       Installing coderay 1.1.0
       Installing diff-lcs 1.2.5
       Installing hitimes 1.2.2
       Installing formatador 0.2.5
       Installing rb-fsevent 0.9.4
       Installing lumberjack 1.0.9
       Installing method_source 0.8.2
       Installing slop 3.6.0
       Installing thor 0.19.1
       Installing rspec-support 3.1.1
       Installing redis 3.1.0
       Installing rack 1.5.2
       Using bundler 1.6.3
       Installing tilt 1.4.1
       Installing timers 4.0.1
       Installing pry 0.10.1
       Installing rspec-core 3.1.5
       Installing rspec-mocks 3.1.2
       Installing rspec-expectations 3.1.2
       Installing rack-protection 1.5.3
       Installing rack-test 0.6.2
       Installing rspec 3.1.0
       Installing celluloid 0.16.0
       Installing sinatra 1.4.5
       Installing ffi 1.9.5
       Installing rb-inotify 0.9.5
       Installing childprocess 0.5.5
       Installing listen 2.7.11
       Installing guard 2.6.1
       Installing guard-rspec 4.3.1
       Your bundle is complete!
       Gems in the group none were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (42.28s)
       Cleaning up the bundler cache.

###### WARNING:
       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.0.0'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.

###### WARNING:
       No Procfile detected, using the default web server (webrick)
       https://devcenter.heroku.com/articles/ruby-default-web-server

+ export REQUIRED_SERVICE_INSTANCES=p-redis:development:redis
+ REQUIRED_SERVICE_INSTANCES=p-redis:development:redis
+ . test_service_instances
++ set +x
+ rspec
Not starting local redis-server, using the one defined in VCAP_SERVICES
...............

Finished in 0.50111 seconds (files took 0.54346 seconds to load)
15 examples, 0 failures

+ cf create-service p-redis development redis
Creating service redis in org development / space development as me...
OK
Service redis already exists
+ cf push redis-example-app --no-start
Using manifest file /var/vcap/store/jenkins_slave/workspace/redis-test-build/manifest.yml

Creating app redis-example-app in org development / space development as me...
OK

Using route redis-example-app.your-cf-installation.example.com
Binding redis-example-app.your-cf-installation.example.com to redis-example-app...
OK

Uploading redis-example-app...
Uploading app files from: /var/vcap/store/jenkins_slave/workspace/redis-test-build
Uploading 17.8M, 3892 files
OK

Endpoint deprecated
+ cf bind-service redis-example-app redis
Binding service redis to app redis-example-app in org development / space development as me...
OK
TIP: Use 'cf push' to ensure your env variable changes take effect
+ cf restart redis-example-app

Starting app redis-example-app in org development / space development as me...
OK
-----> Downloaded app package (17M)
-----> Compiling Ruby/Rack
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
       Purging Cache. Changing stack from  to
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching http://github.com/cloudfoundry/cf-app-utils-ruby.git
       Fetching gem metadata from https://rubygems.org/..........
       Using cf-app-utils 0.3 from http://github.com/cloudfoundry/cf-app-utils-ruby.git (at master)
       Installing tilt 1.4.1
       Using bundler 1.6.3
       Installing redis 3.1.0
       Installing rack 1.5.2
       Installing rack-protection 1.5.3
       Installing sinatra 1.4.5
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (53.43s)
       Cleaning up the bundler cache.
###### WARNING:
       Removing `vendor/bundle`.
       Checking in `vendor/bundle` is not supported. Please remove this directory
       and add it to your .gitignore. To vendor your gems with Bundler, use
       `bundle pack` instead.
###### WARNING:
       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.0.0'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.
###### WARNING:
       No Procfile detected, using the default web server (webrick)
       https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Uploading droplet (13M)
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started

Showing health and status for app redis-example-app in org development / space development as me...
OK

requested state: started
instances: 1/1
usage: 256M x 1 instances
urls: redis-example-app.your-cf-installation.example.com

     state     since                    cpu    memory          disk
#0   running   2014-10-02 04:28:05 PM   0.0%   32.5M of 256M   46M of 1G
+ teardown_test_service_instances
+ set +ex
Finished: SUCCESS

Success!

Visit the URL mentioned above and you should see Not found, which is the home page of our sample app!

Step9

For details on how to use the sample app, visit the Readme.

Was this helpful?
What can we do to improve?
Create a pull request or raise an issue on the source for this page in GitHub