1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-18 05:18:24 +02:00

Merge branch 'master' into pr/allCPEsCanBeUsed2

This commit is contained in:
Thorsten Duda 2019-11-12 12:16:33 +01:00 committed by GitHub
commit 7a9c5c9445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 23 deletions

View File

@ -0,0 +1,37 @@
# ${docGenStepName}
## ${docGenDescription}
## ${docGenParameters}
## ${docGenConfiguration}
## ${docJenkinsPluginDependencies}
## Example
The following Example will create the services specified in a file `manifest-create-service.yml` in cloud foundry org `cfOrg` of Cloud Foundry installation accessed via `https://test.server.com` in space `cfSpace` by using the username & password stored in `cfCredentialsId`.
```groovy
cloudFoundryCreateService(
script: this,
cloudFoundry: [apiEndpoint: 'https://test.server.com',
credentialsId: 'cfCredentialsId',
serviceManifest: 'manifest-create-service.yml',
org: 'cfOrg',
space: 'cfSpace'])
```
The following example additionally to above also makes use of a variable substitution file `mainfest-variable-substitution.yml`.
```groovy
cloudFoundryCreateService(
script: this,
cloudFoundry: [apiEndpoint: 'https://test.server.com',
credentialsId: 'cfCredentialsId',
serviceManifest: 'manifest-create-service.yml',
manifestVariablesFiles: ['mainfest-variable-substitution.yml'],
org: 'cfOrg',
space: 'cfSpace'])
```

View File

@ -187,6 +187,8 @@ steps:
serviceManifest: 'service-manifest.yml' serviceManifest: 'service-manifest.yml'
dockerImage: 'ppiper/cf-cli' dockerImage: 'ppiper/cf-cli'
dockerWorkspace: '/home/piper' dockerWorkspace: '/home/piper'
stashContent:
- 'deployDescriptor'
detectExecuteScan: detectExecuteScan:
detect: detect:
projectVersion: '1' projectVersion: '1'

View File

@ -139,7 +139,7 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli'))
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'"))) assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'")))
assertThat(shellRule.shell, hasItem(containsString(" cf create-service-push --no-push -f 'test.yml'"))) assertThat(shellRule.shell, hasItem(containsString(" cf create-service-push --no-push --service-manifest 'test.yml'")))
assertThat(shellRule.shell, hasItem(containsString("cf logout"))) assertThat(shellRule.shell, hasItem(containsString("cf logout")))
} }
@ -156,16 +156,16 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: 'testSpace', cfSpace: 'testSpace',
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml', cfServiceManifest: 'test.yml',
cfManifestVariablesFiles: [varsFileName], cfManifestVariablesFiles: [varsFileName],
cfManifestVariables: varsList cfManifestVariables: varsList
]) ])
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli'))
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'"))) assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'")))
assertThat(shellRule.shell, hasItem(containsString("cf create-service-push --no-push -f 'test.yml' --var appName='testApplicationFromVarsList' --vars-file 'vars.yml'"))) assertThat(shellRule.shell, hasItem(containsString("cf create-service-push --no-push --service-manifest 'test.yml' --var appName='testApplicationFromVarsList' --vars-file 'vars.yml'")))
assertThat(shellRule.shell, hasItem(containsString("cf logout"))) assertThat(shellRule.shell, hasItem(containsString("cf logout")))
} }
@ -180,9 +180,9 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: 'testSpace', cfSpace: 'testSpace',
cfCredentialsId: 'escape_cfCredentialsId', cfCredentialsId: 'escape_cfCredentialsId',
cfServiceManifest: 'test.yml' cfServiceManifest: 'test.yml'
]) ])
assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'aUserWithA'"'"'' -p 'passHasA'"'"'' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'"""))) assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'aUserWithA'"'"'' -p 'passHasA'"'"'' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'""")))
} }
@ -196,9 +196,9 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: "testSpaceWith'", cfSpace: "testSpaceWith'",
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml' cfServiceManifest: 'test.yml'
]) ])
assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpaceWith'"'"''"""))) assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpaceWith'"'"''""")))
} }
@ -211,9 +211,9 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: "testOrgWith'", cfOrg: "testOrgWith'",
cfSpace: "testSpace", cfSpace: "testSpace",
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml' cfServiceManifest: 'test.yml'
]) ])
assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrgWith'"'"'' -s 'testSpace'"""))) assertThat(shellRule.shell, hasItem(containsString("""cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrgWith'"'"'' -s 'testSpace'""")))
} }
@ -228,12 +228,12 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: 'testSpace', cfSpace: 'testSpace',
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml', cfServiceManifest: 'test.yml',
cfManifestVariables: varsList cfManifestVariables: varsList
]) ])
assertThat(shellRule.shell, hasItem(containsString("""cf create-service-push --no-push -f 'test.yml' --var appName='testApplicationFromVarsListWith'"'"''"""))) assertThat(shellRule.shell, hasItem(containsString("""cf create-service-push --no-push --service-manifest 'test.yml' --var appName='testApplicationFromVarsListWith'"'"''""")))
} }
@Test @Test
@ -248,12 +248,12 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: 'testSpace', cfSpace: 'testSpace',
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml', cfServiceManifest: 'test.yml',
cfManifestVariablesFiles: [varsFileName] cfManifestVariablesFiles: [varsFileName]
]) ])
assertThat(shellRule.shell, hasItem(containsString("""cf create-service-push --no-push -f 'test.yml' --vars-file 'varsWith'"'"'.yml'"""))) assertThat(shellRule.shell, hasItem(containsString("""cf create-service-push --no-push --service-manifest 'test.yml' --vars-file 'varsWith'"'"'.yml'""")))
} }
@Test @Test
@ -271,14 +271,14 @@ class CloudFoundryCreateServiceTest extends BasePiperTest {
deployTool: 'cf_native', deployTool: 'cf_native',
cfOrg: 'testOrg', cfOrg: 'testOrg',
cfSpace: 'testSpace', cfSpace: 'testSpace',
cfCredentialsId: 'test_cfCredentialsId', cfCredentialsId: 'test_cfCredentialsId',
cfServiceManifest: 'test.yml' cfServiceManifest: 'test.yml'
]) ])
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerImage', 'ppiper/cf-cli'))
assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper')) assertThat(dockerExecuteRule.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'"))) assertThat(shellRule.shell, hasItem(containsString("cf login -u 'test_cf' -p '********' -a https://api.cf.eu10.hana.ondemand.com -o 'testOrg' -s 'testSpace'")))
assertThat(shellRule.shell, hasItem(containsString(" cf create-service-push --no-push -f 'test.yml'"))) assertThat(shellRule.shell, hasItem(containsString(" cf create-service-push --no-push --service-manifest 'test.yml'")))
assertThat(shellRule.shell, hasItem(containsString("cf logout"))) assertThat(shellRule.shell, hasItem(containsString("cf logout")))
} }
} }

View File

@ -79,9 +79,10 @@ import static com.sap.piper.Prerequisites.checkScript
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
/** /**
* Uses the Create-Service-Push plugin to create services in a Cloud Foundry space. * Step that uses the CF Create-Service-Push plugin to create services in a Cloud Foundry space. The information about the services is provided in a yaml file as infrastructure as code.
* It is possible to use variable substitution inside of the yaml file like in a CF-push manifest yaml.
* *
* For details how to specify the services see the [github page of the plugin](https://github.com/dawu415/CF-CLI-Create-Service-Push-Plugin). * For more details how to specify the services in the yaml see the [github page of the plugin](https://github.com/dawu415/CF-CLI-Create-Service-Push-Plugin).
* *
* The `--no-push` options is always used with the plugin. To deploy the application make use of the cloudFoundryDeploy step! * The `--no-push` options is always used with the plugin. To deploy the application make use of the cloudFoundryDeploy step!
*/ */
@ -130,7 +131,7 @@ private def executeCreateServicePush(script, Map config) {
set -e set -e
export HOME=${config.dockerWorkspace} export HOME=${config.dockerWorkspace}
cf login -u ${BashUtils.quoteAndEscape(CF_USERNAME)} -p ${BashUtils.quoteAndEscape(CF_PASSWORD)} -a ${config.cloudFoundry.apiEndpoint} -o ${BashUtils.quoteAndEscape(config.cloudFoundry.org)} -s ${BashUtils.quoteAndEscape(config.cloudFoundry.space)}; cf login -u ${BashUtils.quoteAndEscape(CF_USERNAME)} -p ${BashUtils.quoteAndEscape(CF_PASSWORD)} -a ${config.cloudFoundry.apiEndpoint} -o ${BashUtils.quoteAndEscape(config.cloudFoundry.org)} -s ${BashUtils.quoteAndEscape(config.cloudFoundry.space)};
cf create-service-push --no-push -f ${BashUtils.quoteAndEscape(config.cloudFoundry.serviceManifest)}${varPart}${varFilePart} cf create-service-push --no-push --service-manifest ${BashUtils.quoteAndEscape(config.cloudFoundry.serviceManifest)}${varPart}${varFilePart}
""" """
sh "cf logout" sh "cf logout"
if (returnCode!=0) { if (returnCode!=0) {