mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
cloudFoundryDeploy - blue-green plugin extensions (#355)
* cloudFoundryDeploy - blue-green plugin extensions * support blue-green application cleanup with new plugin flag * enhance error reporting in case no app name is available * include PR feedback
This commit is contained in:
parent
0326dd5f8c
commit
5ec37170fc
@ -125,7 +125,7 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
|
||||
assertThat(jedr.dockerParams.dockerEnvVars, hasEntry('STATUS_CODE', "${200}"))
|
||||
assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"')))
|
||||
assertThat(jscr.shell, hasItem(containsString('cf push "testAppName" -f "test.yml"')))
|
||||
assertThat(jscr.shell, hasItem(containsString("cf push testAppName -f 'test.yml'")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -174,7 +174,7 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
|
||||
assertThat(jedr.dockerParams.dockerEnvVars, hasEntry('STATUS_CODE', "${200}"))
|
||||
assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"')))
|
||||
assertThat(jscr.shell, hasItem(containsString('cf push "testAppName" -f "test.yml"')))
|
||||
assertThat(jscr.shell, hasItem(containsString("cf push testAppName -f 'test.yml'")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -197,7 +197,7 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
])
|
||||
// asserts
|
||||
assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"')))
|
||||
assertThat(jscr.shell, hasItem(containsString('cf push -f "test.yml"')))
|
||||
assertThat(jscr.shell, hasItem(containsString("cf push -f 'test.yml'")))
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -222,6 +222,53 @@ class CloudFoundryDeployTest extends BasePiperTest {
|
||||
])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCfNativeBlueGreen() {
|
||||
|
||||
jryr.registerYaml('test.yml', "applications: [[]]")
|
||||
|
||||
jsr.step.cloudFoundryDeploy([
|
||||
script: nullScript,
|
||||
juStabUtils: utils,
|
||||
deployTool: 'cf_native',
|
||||
deployType: 'blue-green',
|
||||
cfOrg: 'testOrg',
|
||||
cfSpace: 'testSpace',
|
||||
cfCredentialsId: 'test_cfCredentialsId',
|
||||
cfAppName: 'testAppName',
|
||||
cfManifest: 'test.yml'
|
||||
])
|
||||
|
||||
assertThat(jedr.dockerParams, hasEntry('dockerImage', 's4sdk/docker-cf-cli'))
|
||||
assertThat(jedr.dockerParams, hasEntry('dockerWorkspace', '/home/piper'))
|
||||
|
||||
assertThat(jscr.shell, hasItem(containsString('cf login -u "test_cf" -p \'********\' -a https://api.cf.eu10.hana.ondemand.com -o "testOrg" -s "testSpace"')))
|
||||
assertThat(jscr.shell, hasItem(containsString("cf blue-green-deploy testAppName --delete-old-apps -f 'test.yml'")))
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testCfNativeWithoutAppNameBlueGreen() {
|
||||
|
||||
helper.registerAllowedMethod('fileExists', [String.class], { s -> return true })
|
||||
jryr.registerYaml('test.yml', "applications: [[]]")
|
||||
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage('[cloudFoundryDeploy] ERROR: Blue-green plugin requires app name to be passed (see https://github.com/bluemixgaragelondon/cf-blue-green-deploy/issues/27)')
|
||||
|
||||
jsr.step.cloudFoundryDeploy([
|
||||
script: nullScript,
|
||||
juStabUtils: utils,
|
||||
deployTool: 'cf_native',
|
||||
deployType: 'blue-green',
|
||||
cfOrg: 'testOrg',
|
||||
cfSpace: 'testSpace',
|
||||
cfCredentialsId: 'test_cfCredentialsId',
|
||||
cfManifest: 'test.yml'
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testMta() {
|
||||
jsr.step.cloudFoundryDeploy([
|
||||
|
@ -126,6 +126,9 @@ def deployCfNative (config) {
|
||||
|
||||
// check if appName is available
|
||||
if (config.cloudFoundry.appName == null || config.cloudFoundry.appName == '') {
|
||||
if (config.deployType == 'blue-green') {
|
||||
error "[${STEP_NAME}] ERROR: Blue-green plugin requires app name to be passed (see https://github.com/bluemixgaragelondon/cf-blue-green-deploy/issues/27)"
|
||||
}
|
||||
if (fileExists(config.cloudFoundry.manifest)) {
|
||||
def manifest = readYaml file: config.cloudFoundry.manifest
|
||||
if (!manifest || !manifest.applications || !manifest.applications[0].name)
|
||||
@ -141,11 +144,7 @@ def deployCfNative (config) {
|
||||
export HOME=${config.dockerWorkspace}
|
||||
cf login -u \"${username}\" -p '${password}' -a ${config.cloudFoundry.apiEndpoint} -o \"${config.cloudFoundry.org}\" -s \"${config.cloudFoundry.space}\"
|
||||
cf plugins
|
||||
cf ${deployCommand} ${config.cloudFoundry.appName?"\"${config.cloudFoundry.appName}\"":''} -f \"${config.cloudFoundry.manifest}\" ${config.smokeTest}"""
|
||||
def retVal = sh script: "cf app \"${config.cloudFoundry.appName}-old\"", returnStatus: true
|
||||
if (retVal == 0) {
|
||||
sh "cf delete \"${config.cloudFoundry.appName}-old\" -r -f"
|
||||
}
|
||||
cf ${deployCommand} ${config.cloudFoundry.appName?:''} ${config.deployType == 'blue-green'?'--delete-old-apps':''} -f '${config.cloudFoundry.manifest}' ${config.smokeTest}"""
|
||||
sh "cf logout"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user