1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00
sap-jenkins-library/documentation/docs/steps/cloudFoundryCreateService.md
Laura Veinberga e83a380c09
SAP CP to SAP BTP Rebranding (#2703)
* Update configuration.md

* Update build.md

* Update cloneRepositories.md

* Update integrationTest.md

* Update post.md

* Update prepareSystem.md

* Update publish.md

* Update configuration.md

* Update configuration.md

* Update introduction.md

* Update build.md

* Update CAP_Scenario.md

* Update CAP_Scenario.md

* Update abapEnvironmentAddons.md

* Update abapEnvironmentAddons.md

* Update abapEnvironmentTest.md

* Update changeManagement.md

* Update Readme.md

* Update Readme.md

* Update introduction.md

* Update abapEnvironmentAssembleConfirm.md

* Update abapEnvironmentAssemblePackages.md

* Update abapEnvironmentCheckoutBranch.md

* Update abapEnvironmentCloneGitRepo.md

* Update abapEnvironmentCreateSystem.md

* Update abapEnvironmentPullGitRepo.md

* Update abapEnvironmentRunATCCheck.md

* Update cloudFoundryCreateService.md

* Update cloudFoundryCreateSpace.md

* Update cloudFoundryDeleteSpace.md

* Update mtaBuild.md

* Update neoDeploy.md

* Update protecodeExecuteScan.md

* Update uiVeri5ExecuteTests.md

* Update guidedtour.md

* Update index.md

* Update configuration.md

* Update guidedtour.md

* Update configuration.md

* Update build.md

* Update CAP_Scenario.md

* Update TMS_Extension.md

* Update TMS_Extension.md

* Update abapEnvironmentAddons.md

* Update abapEnvironmentTest.md

* Update Readme.md

* Update Readme.md

* Update cloudFoundryDeploy.md

* Update influxWriteData.md

* Update neoDeploy.md

* Update CAP_Scenario.md

* Update TMS_Extension.md

* Update Readme.md

* Update Readme.md

* Update guidedtour.md

* Update guidedtour.md

* Update guidedtour.md

* Update configuration.md

Co-authored-by: Thorsten Duda <thorsten.duda@sap.com>
2021-03-19 10:51:24 +01:00

5.8 KiB

${docGenStepName}

${docGenDescription}

Prerequisites

  • You have a user for the SAP BTP Cloud Foundry environment
  • Credentials have been configured in Jenkins with a dedicated Id

${docGenParameters}

${docGenConfiguration}

${docJenkinsPluginDependencies}

Example

  • Single Service Creation in Cloud Foundry example with JSON-configuration in Jenkinsfile

The following example creates a single Service in Cloud Foundry. It makes use of the cfCreateServiceConfig flag for passing a JSON configuration as an in-line parameter string as well as the cfServiceTags for providing user tags.

You can store the credentials in Jenkins and use the cfCredentialsId parameter to authenticate to Cloud Foundry.

This can be done accordingly:

cloudFoundryCreateService(
    cfApiEndpoint : 'https://test.server.com',
    cfOrg : 'cfOrg',
    cfSpace: 'cfSpace',
    cfCredentialsId: 'cfCredentialsId',
    cfService:  'myService',
    cfServiceInstanceName: 'myServiceInstanceName',
    cfServicePlan: 'myPlan',
    cfCreateServiceConfig: '{\"example\":\"value\",\"example\":\"value\"}',
    cfServiceTags: 'list, of, tags',
    script: this,
)

If you chose to having a dedicated JSON file for the JSON configuration for the cfCreateServiceConfig flag you can do so by referencing the file path accordingly. This file should be stored 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. Such a JSON file with the appropriate step configuration could look as follows:

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

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

The step configuration needs to contain the path to the JSON file:

cloudFoundryCreateService(
    cfApiEndpoint : 'https://test.server.com',
    cfOrg : 'cfOrg',
    cfSpace: 'cfSpace',
    cfCredentialsId: 'cfCredentialsId',
    cfService:  'myService',
    cfServiceInstanceName: 'myServiceInstanceName',
    cfServicePlan: 'myPlan',
    cfCreateServiceConfig: 'createServiceConfig.json',
    cfServiceTags: 'list, of, tags',
    script: this,
)
  • Multiple Service Creation in Cloud Foundry example with manifest file in Jenkinsfile

The following example shows the option to create multiple Services in Cloud Foundry. It makes use of the Cloud Foundry Create-Service-Push Plugin. This is described in above Prerequisites, please check this section for further information regarding its usage. This plugin enables this step to create multiple Cloud Foundry Services in one step.

It requires a dedicated YAML file, e.g. manifest.yml, that contains all the information for creating the services, including their names, service plan and the service broker.

Such a manifest.yml file needs to have the following structure, e.g. for creating three mongoDB Services with the Service Plan v4.0-dev:


---
create-services:
- name:   "testDatabase1"
  broker: "mongodb"
  plan:   "v4.0-dev"

- name:   "testDatabase2"
  broker: "mongodb"
  plan:   "v4.0-dev"

- name:   "testDatabase3"
  broker: "mongodb"
  plan:   "v4.0-dev"

The path of the manifest.yml config file needs to be passed as a parameter in the serviceManifest flag. You can store the credentials in Jenkins and use the cfCredentialsId parameter to authenticate to Cloud Foundry.

This can be done accordingly:

cloudFoundryCreateService(
    cfApiEndpoint : 'https://test.server.com',
    cfOrg : 'cfOrg',
    cfSpace: 'cfSpace',
    cfCredentialsId: 'cfCredentialsId',
    serviceManifest: 'manifest.yml',
    script: this,
)
  • Multiple Service Creation in Cloud Foundry example with manifest file and variable substitution in Jenkinsfile

Additionally the Cloud Foundry Create-Service-Push Plugin offers the option to make use of variable substitution. This enables you to rename variables in the manifest.yml dynamically. It can be done either via providing the file path to a dedicated YAML file containing the information regarding the variable substitution values in the manifestVariablesFiles flag or via providing a String List in the manifestVariables flag. Either ways can be achieved as seen in below examples for creating MongoDB instances.

For both ways you need to adapt the manifest.yml file to be relevant for variable substitution. This can be done according to below example:


---
create-services:
- name:   ((name1))
  broker: "mongodb"
  plan:   "v4.0-dev"

- name:   ((name2))
  broker: "mongodb"
  plan:   "v4.0-dev"

- name:   ((name3))
  broker: "mongodb"
  plan:   "v4.0-dev"

If you chose to have a dedicated file for the variable substitution values, it needs to have the following structure of the vars.yml file:

name1: test1
name2: test2
name3: test3

The path of the manifest.yml config file needs to be passed as a parameter in the serviceManifest flag as well as the path to the vars.yml file in the manifestVariablesFiles flag. You can store the credentials in Jenkins and use the cfCredentialsId parameter to authenticate to Cloud Foundry.

This can be done accordingly:

cloudFoundryCreateService(
    cfApiEndpoint : 'https://test.server.com',
    cfOrg : 'cfOrg',
    cfSpace: 'cfSpace',
    cfCredentialsId: 'cfCredentialsId',
    serviceManifest: 'manifest.yml',
    manifestVariablesFiles: 'vars.yml',
    script: this,
)

You can also pass the values for the variable substition as a string list for the manifestVariables flag. This needs to follow the pattern key=value. This can be done accordingly:

cloudFoundryCreateService(
    cfApiEndpoint : 'https://test.server.com',
    cfOrg : 'cfOrg',
    cfSpace: 'cfSpace',
    cfCredentialsId: 'cfCredentialsId',
    serviceManifest: 'manifest.yml',
    manifestVariables: ["name1=test1","name2=test2", "name3=test3"],
    script: this,
)