Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
243 lines (190 sloc) 6.79 KB

Yet another Gradle plugin to deploy an application to Cloud Foundry.

Build Status

The purpose of this plugin is to provide ways to manage the deployment of an application to a Cloud Foundry Environment - Be able to deploy, update, start/stop/restart application, attach/remove routes, create/bind services/CUPS.

"Yet another" because the authoritative source of Cloud Foundry Gradle plugin is expected to be with the CF-Java-Client project.

Using the Plugin

Start by looking at a sample project using the plugin here


  • Add a buildscript dependency:

buildscript {
	ext {
		cfAppVersion = '2.3.0-rc.2'
	repositories {
		maven { url "" }
		maven { url "" }
	dependencies {

apply plugin: 'cf-app'

OR Via the new Gradle plugins mechanism:

plugins {
	id "" version "2.3.0-rc.2"
  • Provide the Cloud Foundry connectivity and application details:

cfConfig {
	//CF Details
	ccHost = ""
	ccUser = "admin"
	ccPassword = "admin"
	org = "pcfdev-org"
	space = "pcfdev-space"

	//Proxy settings (optional)
	cfProxySettings {
		proxyHost = ""
		proxyPort = 1234
		proxyUser = "user"
		proxyPassword = "password"

	//Manifest with defaults (only supports one application per manifest file)
	manifestFile = "manifest.yml"

	//App Details (will override manifest defaults)
	name = "cf-show-env"
	filePath = "build/libs/cf-show-env-0.1.2-SNAPSHOT.jar"
	routes = [ "", "" ]
	instances = 2
	memory = 512

	//Env and services
	buildpack = ""
	environment = ["JAVA_OPTS": "", "SPRING_PROFILES_ACTIVE": "cloud"]
	services  = ["mydb"]
  • Run the task(s):

./gradlew cf-push
  • Override the values using explicit gradle properties, they follow a cf.* pattern:

./gradlew cf-push -Pcf.environment.SPRING_PROFILES_ACTIVE="cloud,dev"
  • User and Password can be overridden using environment variables:

export CF_CCUSER=admin
export CF_CCPASSWORD=admin
./gradlew cf-push
  • There is one task to retrieve the details of an application (cf-get-app-detail). You can use this task in the following way, say to retrieve the app url’s in a gradle task:

task showAppUrls(dependsOn: "cf-get-app-detail") << {
	print "${project.cfConfig.applicationDetail.urls}"

or if you want to run an acceptance test you can define a task alone these lines:

task acceptanceTest(type: Test, dependsOn: "cf-get-app-detail")  {
	doFirst() {
		systemProperty "url", "https://${project.cfConfig.applicationDetail.urls[0]}"
	useJUnit {
		includeCategories 'test.AcceptanceTest'
A sample project demonstrating the plugin is availble here

Using the Plugin for a Blue-Green Application Deployment

The plugin natively understands how to perform the steps of a Blue-Green deploy. Just run the following and you should be set for a Blue-Green deploy:

./gradlew cf-push-blue-green

You may want to run smoke tests after a new version of the app with a new route is brought up before replacing the existing app, if so a smoke test dependency can be added in the build.gradle file the following way:

"cf-push-blue-green-1"{finalizedBy "test"}

and run

./gradlew cf-push-blue-green

Using the Plugin for a Autopilot equivalent deployment

The plugin natively understands how to perform the steps of an Autopilot based deploy. Just run the following on the command line:

./gradlew cf-push-autopilot

Creating services

Services can be created and automatically bound to the app in the targeted org and space by providing information the following way:

    cfService {
        name = "p-mysql"
        plan = "512mb"
        instanceName = "test-db"

    cfService {
        name = "p-rabbitmq"
        plan = "standard"
        instanceName = "test-rabbitmq"
        tags = ["tag1", "tag2"]

    cfService {
            name = "nfs"
            plan = "existing"
            instanceName = "test-nfs"
            parameters = [
                "share": ""

    cfUserProvidedService {
        instanceName = "mydb1"
        credentials = ["jdbcUri": "someuri1"]

Usage behind a proxy

If you need to use the plugin behind a proxy you can configure it like this:

cfConfig {
    cfProxySettings {
        proxyHost = ""
        proxyPort = 1234
        proxyUser = "user"
        proxyPassword = "password"

Only proxyHost and proxyPort are mandatory, proxyUser and proxyPassword are optional and the need for them depends on your actual environment.

You can override any of these values from the command line, the pattern is cf.cfProxySettings.*.

List of all Tasks

Table 1. Tasks
Task Description


Pushes an Application to Cloud Foundry


Delete an application from Cloud Foundry


Delete a route from Cloud Foundry


Get the application detail from Cloud Foundry


Add a route for an application


Remove an existing route for an application


Rename an applicaiton


Start an Application


Stop an Application


Restage an Application


Restart an Application


Push with Autopilot steps


Push with Blue-Green steps


Create a set of services

You can’t perform that action at this time.