Skip to content

cloudFoundryCreateServiceKey

cloudFoundryCreateServiceKey

Description

Create CloudFoundryServiceKey

Usage

We recommend to define values of step parameters via .pipeline/config.yml file.
In this case, calling the step is essentially reduced to defining the step name.
Calling the step can be done either in an orchestrator specific way (e.g. via a Jenkins library step) or on the command line.

library('piper-lib-os')

cloudFoundryCreateServiceKey script: this
piper cloudFoundryCreateServiceKey

Prerequisites

  • 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.

Parameters

Overview - Step

Name Mandatory Additional information
cfApiEndpoint yes
cfOrg yes
cfServiceInstance yes
cfServiceKeyName yes
cfSpace yes
password (yes) Vault Secret pass via ENV, Vault or Jenkins credentials (cfCredentialsId)
script (yes) Jenkins only reference to Jenkins main pipeline script
username (yes) Vault Secret pass via ENV, Vault or Jenkins credentials (cfCredentialsId)
cfAsync no
cfServiceKeyConfig no
verbose no activates debug output

Overview - Execution Environment

Orchestrator-specific only

These parameters are relevant for orchestrator usage and not considered when using the command line option.

Name Mandatory Additional information
containerCommand no Jenkins only
containerShell no Jenkins only
dockerEnvVars no
dockerImage no
dockerName no
dockerOptions no
dockerPullImage no
dockerVolumeBind no Jenkins only
dockerWorkspace no Jenkins only

Details

cfApiEndpoint

Cloud Foundry API endpoint

back to overview

Scope Details
Aliases cloudFoundry/apiEndpoint
Type string
Mandatory yes
Default $PIPER_cfApiEndpoint (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfAsync

Decides if the service key creation runs asynchronously

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default true
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfOrg

CF org

back to overview

Scope Details
Aliases cloudFoundry/org
Type string
Mandatory yes
Default $PIPER_cfOrg (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfServiceInstance

Parameter for CloudFoundry Service Instance Name

back to overview

Scope Details
Aliases cloudFoundry/serviceInstance
Type string
Mandatory yes
Default $PIPER_cfServiceInstance (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfServiceKeyConfig

Path to JSON config file path or JSON in-line string for Cloud Foundry Service Key creation

back to overview

Scope Details
Aliases cloudFoundry/serviceKeyConfig
Type string
Mandatory no
Default $PIPER_cfServiceKeyConfig (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

cfServiceKeyName

Parameter for Service Key name for CloudFoundry Service Key to be created

back to overview

Scope Details
Aliases - cloudFoundry/serviceKey
- cloudFoundry/serviceKeyName
- cfServiceKey
Type string
Mandatory yes
Default $PIPER_cfServiceKeyName (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfSpace

CF Space

back to overview

Scope Details
Aliases cloudFoundry/space
Type string
Mandatory yes
Default $PIPER_cfSpace (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

containerCommand

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Allows to specify start command for container created with dockerImage parameter to overwrite Piper default (/usr/bin/tail -f /dev/null).

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

containerShell

Jenkins-specific: Used for proper environment setup.

Allows to specify the shell to be executed for container with containerName.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerEnvVars

Jenkins-specific: Used for proper environment setup.

Environment variables to set in the container, e.g. [http_proxy: "proxy:8080"].

back to overview

Scope Details
Aliases -
Type map[string]string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerImage

Jenkins-specific: Used for proper environment setup.

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.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default ppiper/cf-cli:latest
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerName

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Name of the container launching dockerImage. SideCar only: Name of the container in local network.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default cf
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerOptions

Jenkins-specific: Used for proper environment setup.

Docker options to be set when starting the container.

back to overview

Scope Details
Aliases -
Type []string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerPullImage

Jenkins-specific: Used for proper environment setup.

Set this to 'false' to bypass a docker image pull. Useful during development process. Allows testing of images which are available in the local registry only.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default true
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerVolumeBind

Jenkins-specific: Used for proper environment setup.

Volumes that should be mounted into the docker container.

back to overview

Scope Details
Aliases -
Type map[string]string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

dockerWorkspace

Jenkins-specific: Used for proper environment setup.

Kubernetes only: Specifies a dedicated user home directory for the container which will be passed as value for environment variable HOME.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

password

User Password for CF User

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_password (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references Jenkins credential id:
  id: cfCredentialsId
  reference to: password

Vault paths:
  • $(vaultPath)/cloudfoundry-$(org)-$(space)
  • $(vaultBasePath)/$(vaultPipelineName)/cloudfoundry-$(org)-$(space)
  • $(vaultBasePath)/GROUP-SECRETS/cloudfoundry-$(org)-$(space)

script

Jenkins-specific: Used for proper environment setup.

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.

back to overview

Scope Details
Aliases -
Type Jenkins Script
Mandatory yes
Default
Secret no
Configuration scope
  • ☐ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

username

User or E-Mail for CF

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_username (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references Jenkins credential id:
  id: cfCredentialsId
  reference to: username

Vault paths:
  • $(vaultPath)/cloudfoundry-$(org)-$(space)
  • $(vaultBasePath)/$(vaultPipelineName)/cloudfoundry-$(org)-$(space)
  • $(vaultBasePath)/GROUP-SECRETS/cloudfoundry-$(org)-$(space)

verbose

verbose output

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

cfCredentialsId

Jenkins-specific: Used for proper environment setup. See using credentials for details.

Jenkins 'Username with password' credentials ID containing user and password to authenticate to the Cloud Foundry API.

back to overview

Scope Details
Aliases -
Type string
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages

Examples

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.

cloudFoundryCreateServiceKey(
  cfApiEndpoint: 'https://test.server.com',
  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:

{
  "example":"value",
  "example":"value"
}

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.

cloudFoundryCreateServiceKey(
  cfApiEndpoint: 'https://test.server.com',
  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:

cloudFoundryCreateServiceKey(
  script: this,
)

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

steps:
    cloudFoundryCreateServiceKey:
        cfApiEndpoint: 'https://test.server.com'
        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'