Skip to content



Create CloudFoundryServiceKey


  • This step is for creating a Service Key for an existing Service in Cloud Foundry.
  • Cloud Foundry API endpoint, Organization, Space, user and Service Instance are available
  • Credentials have been configured in Jenkins with a dedicated Id
  • Additionally you can set the optional serviceKeyConfig flag to configure the Service Key creation with your respective JSON configuration. The JSON configuration can either be a JSON or the path a dedicated JSON configuration file containing the JSON configuration. If you chose a dedicated config file, it must be stored in a file that must be referenced in the serviceKeyConfigFile flag. You must store the file in the same folder as your Jenkinsfile that starts the Pipeline in order for the Pipeline to be able to find the file. Most favourable SCM is Git.


name mandatory default possible values
cfApiEndpoint Yes
cfCredentialsId Yes
cfOrg Yes
cfServiceInstance Yes
cfServiceKeyConfig No
cfServiceKeyName Yes
cfSpace Yes
dockerEnvVars No []
dockerImage No ppiper/cf-cli
dockerName No cf
dockerOptions No []
dockerPullImage No false
dockerWorkspace No /home/piper
password Yes
script Yes
username Yes
verbose No false true, false
  • cfApiEndpoint: Cloud Foundry API endpoint
  • cfCredentialsId: Jenkins credentials ID containing user and password to authenticate to the Cloud Foundry API
  • cfOrg: CF org
  • cfServiceInstance: Parameter for CloudFoundry Service Instance Name
  • cfServiceKeyConfig: Path to JSON config file path or JSON in-line string for Cloud Foundry Service Key creation
  • cfServiceKeyName: Parameter for Service Key name for CloudFoundry Service Key to be created
  • cfSpace: CF Space
  • dockerEnvVars: Environment variables to set in the container, e.g. [http_proxy: "proxy:8080"].
  • dockerImage: Name of the docker image that should be used. If empty, Docker is not used and the command is executed directly on the Jenkins system.
  • dockerName: Kubernetes only: Name of the container launching dockerImage. SideCar only: Name of the container in local network.
  • dockerOptions: Docker options to be set when starting the container.
  • dockerPullImage: Set this to 'false' to bypass a docker image pull. Usefull during development process. Allows testing of images which are available in the local registry only.
  • dockerWorkspace: Kubernetes only: Specifies a dedicated user home directory for the container which will be passed as value for environment variable HOME.
  • password: User Password for CF User
  • script: The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the this parameter, as in script: this. This allows the function to access the commonPipelineEnvironment for retrieving, e.g. configuration parameters.
  • username: User or E-Mail for CF
  • verbose: verbose output

Step Configuration

We recommend to define values of step parameters via config.yml file.

In following sections of the config.yml the configuration is possible:

parameter general step/stage
cfApiEndpoint X X
cfOrg X X
cfServiceInstance X X
cfServiceKeyConfig X
cfServiceKeyName X X
cfSpace X X
dockerEnvVars X
dockerImage X
dockerName X
dockerOptions X
dockerPullImage X
dockerWorkspace X
password X
username X
verbose X


The following examples will create a Service Key named "myServiceKey" for the Service Instance "myServiceInstance" in the provided Cloud Foundry Organization and Space. For the Service Key creation in these example, the serviceKeyConfig parameter is used. It will show the different ways of passing the JSON configuration, either via a string or the path to a file containing the JSON configuration. If you dont want to use a special configuration simply remove the parameter since it is optional.

Create Service Key with JSON config file in Jenkinsfile

This example covers the parameters for a Jenkinsfile when using the cloudFoundryCreateServiceKey step. It uses a serviceKeaConfig.json file with valid JSON objects for creating a Cloud Foundry Service Key.

  cfApiEndpoint: '',
  cfCredentialsId: 'cfCredentialsId',
  cfOrg: 'cfOrg',
  cfSpace: 'cfSpace',
  cfServiceInstance: 'myServiceInstance',
  cfServiceKeyName: 'myServiceKey',
  cfServiceKeyConfig: 'serviceKeyConfig.json',
  script: this,

The JSON config file, e.g. serviceKeyConfig.json can look like this:


Create Service Key with JSON string in Jenkinsfile

The following example covers the creation of a Cloud Foundry Service Key in a Jenkinsfile with using a JSON string as a config for the Service Key creation. If you use a Jenkinsfile for passing the parameter values you need to escape the double quotes in the JSON config string.

  cfApiEndpoint: '',
  cfCredentialsId: 'cfCredentialsId',
  cfOrg: 'cfOrg',
  cfSpace: 'cfSpace',
  cfServiceInstance: 'myServiceInstance',
  cfServiceKeyName: 'myServiceKey',
  cfServiceKeyConfig: '{\"example\":\"value\",\"example\":\"value\"}',
  script: this,

Create Service Key with JSON string as parameter in .pipeline/config.yml file

If you chose to provide a config.yml file you can provide the parameters including the values in this file. You only need to set the script parameter when calling the step:

  script: this,

The .pipeline/config.yml has to contain the following parameters accordingly:

        cfApiEndpoint: ''
        cfOrg: 'testOrg'
        cfSpace: 'testSpace'
        cfServiceInstance: 'testInstance'
        cfServiceKeyName: 'myServiceKey'
        cfServiceKeyConfig: '{"example":"value","example":"value"}'
        cfCredentialsId: 'cfCredentialsId'

When using a .pipeline/config.yml file you don't need to escape the double quotes in the JSON config string. You can also pass the path to a JSON config file in the cfServiceKeyConfig parameter. Example: cfServiceKeyConfig: 'serviceKeyconfig.json'