mirror of
https://github.com/SAP/jenkins-library.git
synced 2026-06-19 22:58:55 +02:00
setupCommonPipelineEnvironment: support yaml config file ending (#811)
* Allow for yaml file ending * Format code
This commit is contained in:
@@ -3,18 +3,13 @@ import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.RuleChain
|
||||
import org.yaml.snakeyaml.Yaml
|
||||
|
||||
import com.sap.piper.Utils
|
||||
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
import util.JenkinsReadYamlRule
|
||||
import util.JenkinsStepRule
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
import static org.junit.Assert.assertNotNull
|
||||
|
||||
|
||||
class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
||||
|
||||
def usedConfigFile
|
||||
@@ -33,7 +28,7 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
||||
|
||||
helper.registerAllowedMethod("readYaml", [Map], { Map parameters ->
|
||||
Yaml yamlParser = new Yaml()
|
||||
if(parameters.text) {
|
||||
if (parameters.text) {
|
||||
return yamlParser.load(parameters.text)
|
||||
}
|
||||
usedConfigFile = parameters.file
|
||||
@@ -55,5 +50,20 @@ class SetupCommonPipelineEnvironmentTest extends BasePiperTest {
|
||||
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testWorksAlsoWithYamlFileEnding() throws Exception {
|
||||
|
||||
helper.registerAllowedMethod("fileExists", [String], { String path ->
|
||||
return path.endsWith('.pipeline/config.yaml')
|
||||
})
|
||||
|
||||
stepRule.step.setupCommonPipelineEnvironment(script: nullScript)
|
||||
|
||||
assertEquals('.pipeline/config.yaml', usedConfigFile)
|
||||
assertNotNull(nullScript.commonPipelineEnvironment.configuration)
|
||||
assertEquals('develop', nullScript.commonPipelineEnvironment.configuration.general.productiveBranch)
|
||||
assertEquals('my-maven-docker', nullScript.commonPipelineEnvironment.configuration.steps.mavenExecute.dockerImage)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,10 +60,13 @@ void call(Map parameters = [:]) {
|
||||
private loadConfigurationFromFile(script, String configFile) {
|
||||
|
||||
String defaultYmlConfigFile = '.pipeline/config.yml'
|
||||
String defaultYamlConfigFile = '.pipeline/config.yaml'
|
||||
|
||||
if (configFile) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: configFile)
|
||||
} else if (fileExists(defaultYmlConfigFile)) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: defaultYmlConfigFile)
|
||||
} else if (fileExists(defaultYamlConfigFile)) {
|
||||
script.commonPipelineEnvironment.configuration = readYaml(file: defaultYamlConfigFile)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user