1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-05 15:15:44 +02:00

Merge remote-tracking branch 'github/master' into HEAD

This commit is contained in:
Marcus Holl 2018-12-19 13:18:00 +01:00
commit d6372d5d96
6 changed files with 70 additions and 23 deletions

View File

@ -2,7 +2,7 @@
## Description
Application will be deployed to a test or production space within Cloud Foundry.
The application will be deployed to a test or production space within Cloud Foundry.
Deployment can be done
* in a standard way
@ -14,7 +14,7 @@ Deployment can be done
* Standard `cf push` and [Bluemix blue-green plugin](https://github.com/bluemixgaragelondon/cf-blue-green-deploy#how-to-use)
* [MTA CF CLI Plugin](https://github.com/cloudfoundry-incubator/multiapps-cli-plugin)
## Prerequsites
## Prerequisites
* Cloud Foundry organization, space and deployment user are available
* Credentials for deployment have been configured in Jenkins with a dedicated Id

View File

@ -46,7 +46,7 @@ Note that a version is formed by `major.minor.patch`, and a version is compatibl
| `script` | yes | | |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
## Parameters when using WAR file deployment method witout .properties file - with parameters (WAR_PARAMS)
## Parameters when using WAR file deployment method without .properties file - with parameters (WAR_PARAMS)
| parameter | mandatory | default | possible values |
| -------------------|-----------|-------------------------------|-------------------------------------------------|

View File

@ -10,6 +10,8 @@ import util.JenkinsStepRule
import util.JenkinsReadYamlRule
import util.Rules
import static org.hamcrest.Matchers.is
import static org.junit.Assert.assertThat
import static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals
@ -96,4 +98,22 @@ class InfluxWriteDataTest extends BasePiperTest {
assertJobStatusSuccess()
}
@Test
void testInfluxWriteDataWrapInNode() throws Exception {
boolean nodeCalled = false
helper.registerAllowedMethod('node', [String.class, Closure.class]) {s, body ->
nodeCalled = true
return body()
}
helper.registerAllowedMethod("deleteDir", [], null)
nullScript.commonPipelineEnvironment.setArtifactVersion('1.2.3')
jsr.step.influxWriteData(script: nullScript, wrapInNode: true)
assertThat(nodeCalled, is(true))
}
}

View File

@ -40,7 +40,7 @@ public class MtaBuildTest extends BasePiperTest {
@Before
void init() {
helper.registerAllowedMethod('fileExists', [String], { s -> false })
helper.registerAllowedMethod('fileExists', [String], { s -> s == 'mta.yaml' })
jscr.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*\\$MTA_JAR_LOCATION.*', '')
jscr.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*\\$JAVA_HOME.*', '')
@ -97,9 +97,10 @@ public class MtaBuildTest extends BasePiperTest {
@Test
void noMtaPresentTest() {
jryr.registerYaml('mta.yaml', { throw new FileNotFoundException() })
thrown.expect(FileNotFoundException)
helper.registerAllowedMethod('fileExists', [String], { false })
thrown.expect(AbortException)
thrown.expectMessage('\'mta.yaml\' not found in project sources and \'applicationName\' not provided as parameter ' +
'- cannot generate \'mta.yaml\' file.')
jsr.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
}

View File

@ -13,7 +13,8 @@ import groovy.transform.Field
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = [
'influxServer',
'influxPrefix'
'influxPrefix',
'wrapInNode'
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
'artifactVersion'
@ -27,7 +28,7 @@ void call(Map parameters = [:]) {
script = this
// load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this)
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
@ -39,29 +40,51 @@ void call(Map parameters = [:]) {
.use()
new Utils().pushToSWA([step: STEP_NAME,
stepParam1: parameters?.script == null], configuration)
stepParam1: parameters?.script == null], config)
if (!configuration.artifactVersion) {
if (!config.artifactVersion) {
//this takes care that terminated builds due to milestone-locking do not cause an error
echo "[${STEP_NAME}] no artifact version available -> exiting writeInflux without writing data"
return
}
echo """[${STEP_NAME}]----------------------------------------------------------
Artifact version: ${configuration.artifactVersion}
Influx server: ${configuration.influxServer}
Influx prefix: ${configuration.influxPrefix}
Artifact version: ${config.artifactVersion}
Influx server: ${config.influxServer}
Influx prefix: ${config.influxPrefix}
InfluxDB data: ${script.commonPipelineEnvironment.getInfluxCustomData()}
InfluxDB data map: ${script.commonPipelineEnvironment.getInfluxCustomDataMap()}
[${STEP_NAME}]----------------------------------------------------------"""
if (configuration.influxServer)
step([$class: 'InfluxDbPublisher', selectedTarget: configuration.influxServer, customPrefix: configuration.influxPrefix, customData: script.commonPipelineEnvironment.getInfluxCustomData(), customDataMap: script.commonPipelineEnvironment.getInfluxCustomDataMap()])
//write results into json file for archiving - also benefitial when no InfluxDB is available yet
def jsonUtils = new JsonUtils()
writeFile file: 'jenkins_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomData())
writeFile file: 'pipeline_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomDataMap())
archiveArtifacts artifacts: '*data.json', allowEmptyArchive: true
if(config.wrapInNode){
node(''){
try{
writeToInflux(config, script)
}finally{
deleteDir()
}
}
} else {
writeToInflux(config, script)
}
}
}
private void writeToInflux(config, script){
if (config.influxServer) {
step([
$class: 'InfluxDbPublisher',
selectedTarget: config.influxServer,
customPrefix: config.influxPrefix,
customData: script.commonPipelineEnvironment.getInfluxCustomData(),
customDataMap: script.commonPipelineEnvironment.getInfluxCustomDataMap()
])
}
//write results into json file for archiving - also benefitial when no InfluxDB is available yet
def jsonUtils = new JsonUtils()
writeFile file: 'jenkins_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomData())
writeFile file: 'pipeline_data.json', text: jsonUtils.getPrettyJsonString(script.commonPipelineEnvironment.getInfluxCustomDataMap())
archiveArtifacts artifacts: '*data.json', allowEmptyArchive: true
}

View File

@ -51,11 +51,14 @@ void call(Map parameters = [:]) {
if (!fileExists(mtaYamlName)) {
if (!applicationName) {
echo "'applicationName' not provided as parameter - will not try to generate ${mtaYamlName} file"
error "'${mtaYamlName}' not found in project sources and 'applicationName' not provided as parameter - cannot generate '${mtaYamlName}' file."
} else {
echo "[INFO] '${mtaYamlName}' file not found in project sources, but application name provided as parameter - generating '${mtaYamlName}' file."
MtaUtils mtaUtils = new MtaUtils(this)
mtaUtils.generateMtaDescriptorFromPackageJson("package.json", mtaYamlName, applicationName)
}
} else {
echo "[INFO] '${mtaYamlName}' file found in project sources."
}
def mtaYaml = readYaml file: mtaYamlName