You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-09-16 09:26:22 +02:00
Add capabilities to check for breaking changes in config (#2045)
This change adds the capabilities to check if the user still uses legacy configuration parameters and allows to fail the pipeline in the piperPipelineStageInit in case incompatible configuration is found. Thus, it is now possible to describe breaking changes in the configuration with the use of a yaml resource file. In this file, one can describe the changes in configuration, e.g., when a configuration parameter was replaced or removed. A concrete example for such a file for the Cloud SDK Pipeline is part of this PR.
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
removedOrReplacedConfigKeys:
|
||||
extensionRepository:
|
||||
newConfigKey: "globalExtensionsRepository"
|
||||
general: true
|
||||
customMessage: "To configure a version please use globalExtensionsVersion.
|
||||
You can also configure globalExtensionsRepositoryCredentialsId in case the extension repository is secured.
|
||||
Please note that you can also configure these values as part of your custom defaults / shared configuration."
|
||||
globalSettingsFile:
|
||||
steps: ["mavenExecute"]
|
||||
customMessage: "The SAP Cloud SDK Pipeline uses an own global settings file to inject its download proxy as maven repository mirror.
|
||||
Please only specify the settings via the parameter 'projectSettingsFile'"
|
||||
orgToken:
|
||||
newConfigKey: "credentialsId"
|
||||
stages: ["whitesourceScan"]
|
||||
customMessage: "Store it as a 'Secret Text' in Jenkins and use the 'credentialsId' field instead."
|
||||
archiveDebugLog:
|
||||
postAction: true
|
||||
customMessage: "Please use the step configuration for debugReportArchive instead."
|
||||
tmsUpload:
|
||||
stages: ["productionDeployment"]
|
||||
customMessage: "Since version v39 it is required to configure the step tmsUpload instead.
|
||||
Details can be found in the release notes at https://github.com/SAP/cloud-s4-sdk-pipeline/releases/tag/v39 as well as in the step documentation: https://sap.github.io/jenkins-library/steps/tmsUpload/."
|
||||
sharedConfiguration:
|
||||
newConfigKey: "customDefaults"
|
||||
general: true
|
||||
customMessage: "In addition please move it to the root level of the config file, i.e. before the 'general' section.
|
||||
The value of this key needs to be a list of strings.
|
||||
See also https://sap.github.io/jenkins-library/configuration/#custom-default-configuration for more information.
|
||||
As an example for the necessary change, please consult the release notes of v33 at https://github.com/SAP/cloud-s4-sdk-pipeline/releases/tag/v33"
|
||||
automaticVersioning:
|
||||
general: true
|
||||
customMessage: "Please configure the artifactPrepareVersion step instead.
|
||||
Details can be found in the release notes of v37 of the pipeline: https://github.com/SAP/cloud-s4-sdk-pipeline/releases/tag/v37"
|
||||
sapNpmRegistry:
|
||||
steps: ["executeNpm", "npmExecuteScripts", "npmExecuteLint", "mtaBuild"]
|
||||
warnInsteadOfError: true
|
||||
customMessage: "The parameter will be ignored during execution.
|
||||
This configuration option was removed in version v41, since the packages of the public SAP NPM Registry were migrated to the default public registry at npmjs.org.
|
||||
Please configure the defaultNpmRegistry parameter instead, in case a custom NPM registry configuration is required."
|
||||
|
||||
removedOrReplacedSteps:
|
||||
executeMaven:
|
||||
newStepName: "mavenExecute"
|
||||
deployToCfWithCli:
|
||||
newStepName: "cloudFoundryDeploy"
|
||||
deployToNeoWithCli:
|
||||
newStepName: "deployToNeoWithCli"
|
||||
executeFortifyScan:
|
||||
newStepName: "fortifyExecuteScan"
|
||||
artifactSetVersion:
|
||||
newStepName: "artifactPrepareVersion"
|
||||
onlyCheckProjectConfig: true
|
||||
customMessage: "Details can be found in the release notes of v37 of the pipeline: https://github.com/SAP/cloud-s4-sdk-pipeline/releases/tag/v37"
|
||||
createHdiContainer:
|
||||
customMessage: "The backendIntegrationTests stage has been aligned with project 'Piper' in version v41 and activation of the createHdiContainer step was not migrated.
|
||||
If you still need the functionalities provided by the createHdiContainer step, please open an issue at: https://github.com/SAP/cloud-s4-sdk-pipeline/issues/new?template=pipeline-issue.md
|
||||
Apart from that it is also possible to implement an extension for the backendIntegrationTests stage using the extensibility concept explained in the documentation: https://sap.github.io/jenkins-library/extensibility/
|
||||
For the time being, the step createHdiContainer is still available in the Pipeline and can be called from an extension.
|
||||
The extension must pass all required options to the step via parameters, it cannot be configured in your .pipeline/config.yml."
|
||||
|
||||
removedOrReplacedStages:
|
||||
integrationTests:
|
||||
newStageName: "backendIntegrationTests"
|
||||
staticCodeChecks:
|
||||
customMessage: "Since version v32 it is required to migrate the configuration into your pom.xml file or to the configuration of the new step mavenExecuteStaticCodeChecks.
|
||||
Details can be found in the release notes as well as in the step documentation: https://sap.github.io/jenkins-library/steps/mavenExecuteStaticCodeChecks/."
|
||||
fortifyScan:
|
||||
customMessage: "To configure fortify please use the step configuration for fortifyExecuteScan.
|
||||
Details can be found in the documentation: https://sap.github.io/jenkins-library/steps/fortifyExecuteScan/"
|
||||
lint:
|
||||
customMessage: "Since version v43 it is required to configure the step npmExecuteLint instead.
|
||||
Details can be found in the release notes as well as in the step documentation: https://sap.github.io/jenkins-library/steps/npmExecuteLint/."
|
||||
frontendUnitTests:
|
||||
newStageName: "additionalUnitTests"
|
||||
sonarQubeScan:
|
||||
newStageName: "compliance"
|
||||
|
||||
parameterTypeChanged:
|
||||
appUrls:
|
||||
oldType: "String"
|
||||
newType: "List"
|
||||
stages: ["productionDeployment", "endToEndTests"]
|
||||
|
||||
renamedNpmScript:
|
||||
ci-integration-test:
|
||||
newScriptName: "ci-it-backend"
|
||||
ci-test:
|
||||
newScriptName: "ci-frontend-unit-test"
|
||||
warnInsteadOfError: true
|
245
src/com/sap/piper/LegacyConfigurationCheckUtils.groovy
Normal file
245
src/com/sap/piper/LegacyConfigurationCheckUtils.groovy
Normal file
@@ -0,0 +1,245 @@
|
||||
package com.sap.piper
|
||||
|
||||
class LegacyConfigurationCheckUtils{
|
||||
static void checkConfiguration(Script script, Map configChanges) {
|
||||
if (configChanges?.removedOrReplacedConfigKeys) {
|
||||
checkForRemovedOrReplacedConfigKeys(script, configChanges.removedOrReplacedConfigKeys)
|
||||
}
|
||||
|
||||
if (configChanges?.removedOrReplacedSteps) {
|
||||
checkForRemovedOrReplacedSteps(script, configChanges.removedOrReplacedSteps)
|
||||
}
|
||||
|
||||
if (configChanges?.removedOrReplacedStages) {
|
||||
checkForRemovedOrReplacedStages(script, configChanges.removedOrReplacedStages)
|
||||
}
|
||||
|
||||
if (configChanges?.parameterTypeChanged) {
|
||||
checkForParameterTypeChanged(script, configChanges.parameterTypeChanged)
|
||||
}
|
||||
|
||||
if (configChanges?.renamedNpmScript) {
|
||||
checkForRenamedNpmScripts(script, configChanges.renamedNpmScript)
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForRemovedOrReplacedConfigKeys(Script script, Map configChanges) {
|
||||
configChanges.each {oldConfigKey, changes ->
|
||||
List steps = changes?.steps ?: []
|
||||
List stages = changes?.stages ?: []
|
||||
Boolean general = changes?.general ?: false
|
||||
Boolean postAction = changes?.postAction ?: false
|
||||
|
||||
Boolean warnInsteadOfError = changes?.warnInsteadOfError ?: false
|
||||
String customMessage = changes?.customMessage ?: ""
|
||||
String newConfigKey = changes?.newConfigKey ?: ""
|
||||
|
||||
if (newConfigKey) {
|
||||
customMessage = "Please use the parameter ${newConfigKey} instead. " + customMessage
|
||||
}
|
||||
|
||||
for (int i = 0; i < steps.size(); i++) {
|
||||
Map config = loadEffectiveStepConfig(script, steps[i])
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
String errorMessage = "Your pipeline configuration contains the configuration key ${oldConfigKey} for the step ${steps[i]}. " +
|
||||
"This configuration option was removed. " + customMessage
|
||||
if (warnInsteadOfError) {
|
||||
addPipelineWarning(script, "Deprecated configuration key ${oldConfigKey}", errorMessage)
|
||||
} else {
|
||||
script.error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
Map config = loadEffectiveStageConfig(script, stages[i])
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
String errorMessage = "Your pipeline configuration contains the configuration key ${oldConfigKey} for the stage ${stages[i]}. " +
|
||||
"This configuration option was removed. " + customMessage
|
||||
if (warnInsteadOfError) {
|
||||
addPipelineWarning(script, "Deprecated configuration key ${oldConfigKey}", errorMessage)
|
||||
} else {
|
||||
script.error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (general) {
|
||||
Map config = loadEffectiveGeneralConfig(script)
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
String errorMessage = "Your pipeline configuration contains the configuration key ${oldConfigKey} in the general section. " +
|
||||
"This configuration option was removed. " + customMessage
|
||||
if (warnInsteadOfError) {
|
||||
addPipelineWarning(script, "Deprecated configuration key ${oldConfigKey}", errorMessage)
|
||||
} else {
|
||||
script.error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (postAction) {
|
||||
Map config = loadEffectivePostActionConfig(script)
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
String errorMessage = "Your pipeline configuration contains the configuration key ${oldConfigKey} in the postActions section. " +
|
||||
"This configuration option was removed. " + customMessage
|
||||
if (warnInsteadOfError) {
|
||||
addPipelineWarning(script, "Deprecated configuration key ${oldConfigKey}", errorMessage)
|
||||
} else {
|
||||
script.error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForRemovedOrReplacedSteps(Script script, Map configChanges) {
|
||||
configChanges.each {oldConfigKey, changes ->
|
||||
Boolean onlyCheckProjectConfig = changes?.onlyCheckProjectConfig ?: false
|
||||
String customMessage = changes?.customMessage ?: ""
|
||||
String newStepName = changes?.newStepName ?: ""
|
||||
|
||||
if (newStepName) {
|
||||
customMessage = "Please configure the step ${newStepName} instead. " + customMessage
|
||||
}
|
||||
|
||||
Map config
|
||||
if (onlyCheckProjectConfig) {
|
||||
config = ConfigurationLoader.stepConfiguration(script, oldConfigKey)
|
||||
} else {
|
||||
config = loadEffectiveStepConfig(script, oldConfigKey)
|
||||
}
|
||||
|
||||
if (config) {
|
||||
script.error("Your pipeline configuration contains configuration for the step ${oldConfigKey}. " +
|
||||
"This step has been removed. " + customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForRemovedOrReplacedStages(Script script, Map configChanges) {
|
||||
configChanges.each {oldConfigKey, changes ->
|
||||
String customMessage = changes?.customMessage ?: ""
|
||||
String newStageName = changes?.newStageName ?: ""
|
||||
|
||||
if (newStageName) {
|
||||
customMessage = "Please configure the stage ${newStageName} instead. " + customMessage
|
||||
}
|
||||
|
||||
if (loadEffectiveStageConfig(script, oldConfigKey)) {
|
||||
script.error("Your pipeline configuration contains configuration for the stage ${oldConfigKey}. " +
|
||||
"This stage has been removed. " + customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForParameterTypeChanged(Script script, Map configChanges) {
|
||||
configChanges.each { oldConfigKey, changes ->
|
||||
String oldType = changes?.oldType ?: ""
|
||||
String newType = changes?.newType ?: ""
|
||||
List steps = changes?.steps ?: []
|
||||
List stages = changes?.stages ?: []
|
||||
Boolean general = changes?.general ?: false
|
||||
String customMessage = changes?.customMessage ?: ""
|
||||
|
||||
if (oldType != "String") {
|
||||
script.echo ("Your legacy config settings contain an entry for parameterTypeChanged with the key ${oldConfigKey} with the unsupported type ${oldType}. " +
|
||||
"Currently only the type 'String' is supported.")
|
||||
return
|
||||
}
|
||||
|
||||
for (int i = 0; i < steps.size(); i++) {
|
||||
Map config = loadEffectiveStepConfig(script, steps[i])
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
if (oldType == "String" && config.get(oldConfigKey) instanceof String) {
|
||||
script.error("Your pipeline configuration contains the configuration key ${oldConfigKey} for the step ${steps[i]}. " +
|
||||
"The type of this configuration parameter was changed from ${oldType} to ${newType}. " + customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < stages.size(); i++) {
|
||||
Map config = loadEffectiveStageConfig(script, stages[i])
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
if (oldType == "String" && config.get(oldConfigKey) instanceof String) {
|
||||
script.error("Your pipeline configuration contains the configuration key ${oldConfigKey} for the stage ${stages[i]}. " +
|
||||
"The type of this configuration parameter was changed from ${oldType} to ${newType}. " + customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (general) {
|
||||
Map config = loadEffectiveGeneralConfig(script)
|
||||
if (config.containsKey(oldConfigKey)) {
|
||||
if (oldType == "String" && config.get(oldConfigKey) instanceof String) {
|
||||
script.error("Your pipeline configuration contains the configuration key ${oldConfigKey} in the general section. " +
|
||||
"The type of this configuration parameter was changed from ${oldType} to ${newType}. " + customMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void checkForRenamedNpmScripts(Script script, Map configChanges) {
|
||||
configChanges.each { oldScriptName, changes ->
|
||||
String newScriptName = changes?.newScriptName ?: ""
|
||||
Boolean warnInsteadOfError = changes?.warnInsteadOfError ?: false
|
||||
String customMessage = changes?.customMessage ?: ""
|
||||
|
||||
String packageJsonWithScript = findPackageWithScript(script, oldScriptName)
|
||||
if (packageJsonWithScript) {
|
||||
String errorMessage = "Your package.json file ${packageJsonWithScript} contains an npm script using the deprecated name ${oldScriptName}. " +
|
||||
"Please rename the script to ${newScriptName}, since the script ${oldScriptName} will not be executed by the pipeline anymore. " + customMessage
|
||||
if (warnInsteadOfError) {
|
||||
addPipelineWarning(script, "Deprecated npm script ${oldScriptName}", errorMessage)
|
||||
} else {
|
||||
script.error(errorMessage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String findPackageWithScript(Script script, String scriptName) {
|
||||
List packages = script.findFiles(glob: '**/package.json', excludes: '**/node_modules/**')
|
||||
|
||||
for (int i = 0; i < packages.size(); i++) {
|
||||
String packageJsonPath = packages[i].path
|
||||
Map packageJson = script.readJSON file: packageJsonPath
|
||||
Map npmScripts = packageJson?.scripts ?: [:]
|
||||
if (npmScripts.get(scriptName)) {
|
||||
return packageJsonPath
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
private static Map loadEffectiveStepConfig(Script script, String stepName) {
|
||||
return MapUtils.merge(ConfigurationLoader.defaultStepConfiguration(script, stepName), ConfigurationLoader.stepConfiguration(script, stepName))
|
||||
}
|
||||
|
||||
private static Map loadEffectiveStageConfig(Script script, String stageName) {
|
||||
return MapUtils.merge(ConfigurationLoader.defaultStageConfiguration(script, stageName), ConfigurationLoader.stageConfiguration(script, stageName))
|
||||
}
|
||||
|
||||
private static Map loadEffectiveGeneralConfig(Script script) {
|
||||
return MapUtils.merge(ConfigurationLoader.defaultGeneralConfiguration(script), ConfigurationLoader.generalConfiguration(script))
|
||||
}
|
||||
|
||||
private static Map loadEffectivePostActionConfig(Script script) {
|
||||
Map defaultPostActionConfig = DefaultValueCache.getInstance()?.getDefaultValues()?.get("postActions") ?: [:]
|
||||
Map projectPostActionConfig = script?.commonPipelineEnvironment?.configuration?.postActions ?: [:]
|
||||
return MapUtils.merge(defaultPostActionConfig, projectPostActionConfig)
|
||||
}
|
||||
|
||||
static void addPipelineWarning(Script script, String heading, String message) {
|
||||
script.echo '[WARNING] ' + message
|
||||
script.addBadge(icon: "warning.gif", text: message)
|
||||
|
||||
String html =
|
||||
"""
|
||||
<h2>$heading</h2>
|
||||
<p>$message</p>
|
||||
"""
|
||||
|
||||
script.createSummary(icon: "warning.gif", text: html)
|
||||
}
|
||||
}
|
@@ -0,0 +1,333 @@
|
||||
package com.sap.piper
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
import org.junit.rules.RuleChain
|
||||
import util.BasePiperTest
|
||||
import util.Rules
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
|
||||
|
||||
class LegacyConfigurationCheckUtilsTest extends BasePiperTest {
|
||||
private ExpectedException thrown = ExpectedException.none()
|
||||
String echoOutput = ""
|
||||
|
||||
@Rule
|
||||
public RuleChain ruleChain = Rules
|
||||
.getCommonRules(this)
|
||||
.around(thrown)
|
||||
|
||||
|
||||
@Before
|
||||
void init() {
|
||||
DefaultValueCache.createInstance([
|
||||
steps: [
|
||||
customStep: [
|
||||
param: 'test'
|
||||
]
|
||||
]
|
||||
])
|
||||
helper.registerAllowedMethod('addBadge', [Map], {return})
|
||||
helper.registerAllowedMethod('createSummary', [Map], {return})
|
||||
helper.registerAllowedMethod("echo", [String.class], { s -> echoOutput = s})
|
||||
helper.registerAllowedMethod('findFiles', [Map], {m ->
|
||||
if(m.glob == '**/package.json') {
|
||||
return [new File("package.json")].toArray()
|
||||
} else {
|
||||
return []
|
||||
}
|
||||
})
|
||||
helper.registerAllowedMethod('readJSON', [Map], { m ->
|
||||
if (m.file.contains('package.json')) {
|
||||
return [scripts: [oldNpmScriptName: "echo test",
|
||||
npmScript2: "echo test"]]
|
||||
} else {
|
||||
return [:]
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey for the step someStep. " +
|
||||
"This configuration option was removed. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [someStep: [oldConfigKey: false]]]
|
||||
Map configChanges = [oldConfigKey: [steps: ['someStep'], customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForReplacedConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey for the step someStep. " +
|
||||
"This configuration option was removed. Please use the parameter newConfigKey instead. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [someStep: [oldConfigKey: false]]]
|
||||
Map configChanges = [oldConfigKey: [steps: ['someStep'], newConfigKey: "newConfigKey", customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedConfigKeysWithWarning() {
|
||||
String expectedWarning = "[WARNING] Your pipeline configuration contains the configuration key oldConfigKey for the step someStep. " +
|
||||
"This configuration option was removed. test"
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [someStep: [oldConfigKey: false]]]
|
||||
Map configChanges = [oldConfigKey: [steps: ['someStep'], warnInsteadOfError: true, customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
assertEquals(expectedWarning, echoOutput)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedStageConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey for the stage someStage. " +
|
||||
"This configuration option was removed. ")
|
||||
nullScript.commonPipelineEnvironment.configuration = [stages: [someStage: [oldConfigKey: false]]]
|
||||
Map configChanges = [oldConfigKey: [stages: ['someStage']]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedGeneralConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey in the general section. " +
|
||||
"This configuration option was removed. ")
|
||||
nullScript.commonPipelineEnvironment.configuration = [general: [oldConfigKey: false]]
|
||||
Map configChanges = [oldConfigKey: [general: true]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedPostActionConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey in the postActions section. " +
|
||||
"This configuration option was removed. ")
|
||||
nullScript.commonPipelineEnvironment.configuration = [postActions: [oldConfigKey: false]]
|
||||
Map configChanges = [oldConfigKey: [postAction: true]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedConfigKeys(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForReplacedStep() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the step oldStep. " +
|
||||
"This step has been removed. Please configure the step newStep instead. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [oldStep: [configKey: false]]]
|
||||
Map configChanges = [oldStep: [newStepName: 'newStep', customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedSteps(nullScript, configChanges)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedStep() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the step oldStep. " +
|
||||
"This step has been removed. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [oldStep: [configKey: false]]]
|
||||
Map configChanges = [oldStep: [customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedSteps(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedStepOnlyProjectConfig() {
|
||||
DefaultValueCache.createInstance([
|
||||
steps: [
|
||||
oldStep: [
|
||||
configKey: false
|
||||
]
|
||||
]
|
||||
])
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [newStep: [configKey: false]]]
|
||||
Map configChanges = [oldStep: [onlyCheckProjectConfig: true]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedSteps(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForReplacedStage() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the stage oldStage. " +
|
||||
"This stage has been removed. Please configure the stage newStage instead. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [stages: [oldStage: [configKey: false]]]
|
||||
Map configChanges = [oldStage: [newStageName: 'newStage', customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedStages(nullScript, configChanges)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRemovedStage() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the stage oldStage. " +
|
||||
"This stage has been removed. ")
|
||||
nullScript.commonPipelineEnvironment.configuration = [stages: [oldStage: [configKey: false]]]
|
||||
Map configChanges = [oldStage: []]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRemovedOrReplacedStages(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForStageParameterTypeChanged() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key configKeyOldType for the stage productionDeployment. " +
|
||||
"The type of this configuration parameter was changed from String to List. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [stages: [productionDeployment: [configKeyOldType: "string"]]]
|
||||
Map configChanges = [configKeyOldType: [oldType: "String", newType: "List", stages: ["productionDeployment", "endToEndTests"], customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForParameterTypeChanged(nullScript, configChanges)
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForStepParameterTypeChanged() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key configKeyOldType for the step testStep. " +
|
||||
"The type of this configuration parameter was changed from String to List. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [testStep: [configKeyOldType: "string"]]]
|
||||
Map configChanges = [configKeyOldType: [oldType: "String", newType: "List", steps: ["testStep"], customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForParameterTypeChanged(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForGeneralParameterTypeChanged() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key configKeyOldType in the general section. " +
|
||||
"The type of this configuration parameter was changed from String to List. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [general: [configKeyOldType: "string"]]
|
||||
Map configChanges = [configKeyOldType: [oldType: "String", newType: "List", general: true, customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForParameterTypeChanged(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForUnsupportedParameterTypeChanged() {
|
||||
String expectedWarning = "Your legacy config settings contain an entry for parameterTypeChanged with the key configKeyOldType with the unsupported type Map. " +
|
||||
"Currently only the type 'String' is supported."
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [testStep: [configKeyOldType: [test: true]]]]
|
||||
Map configChanges = [configKeyOldType: [oldType: "Map", newType: "List", steps: ["testStep"], customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForParameterTypeChanged(nullScript, configChanges)
|
||||
assertEquals(expectedWarning, echoOutput)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRenamedNpmScripts() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your package.json file package.json contains an npm script using the deprecated name oldNpmScriptName. " +
|
||||
"Please rename the script to newNpmScriptName, since the script oldNpmScriptName will not be executed by the pipeline anymore. test")
|
||||
Map configChanges = [oldNpmScriptName: [newScriptName: "newNpmScriptName", customMessage: "test"]]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRenamedNpmScripts(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckForRenamedNpmScriptsWithWarning() {
|
||||
Map configChanges = [oldNpmScriptName: [newScriptName: "newNpmScriptName", warnInsteadOfError: true, customMessage: "test"]]
|
||||
String expectedWarning = "[WARNING] Your package.json file package.json contains an npm script using the deprecated name oldNpmScriptName. " +
|
||||
"Please rename the script to newNpmScriptName, since the script oldNpmScriptName will not be executed by the pipeline anymore. test"
|
||||
|
||||
LegacyConfigurationCheckUtils.checkForRenamedNpmScripts(nullScript, configChanges)
|
||||
|
||||
assertEquals(expectedWarning, echoOutput)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckConfigurationRemovedOrReplacedConfigKeys() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key oldConfigKey for the step someStep. " +
|
||||
"This configuration option was removed. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [someStep: [oldConfigKey: false]]]
|
||||
Map configChanges = [
|
||||
removedOrReplacedConfigKeys: [
|
||||
oldConfigKey: [
|
||||
steps: ['someStep'],
|
||||
customMessage: "test"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkConfiguration(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckConfigurationRemovedOrReplacedSteps() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the step oldStep. " +
|
||||
"This step has been removed. Please configure the step newStep instead. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [oldStep: [configKey: false]]]
|
||||
Map configChanges = [
|
||||
removedOrReplacedSteps: [
|
||||
oldStep: [
|
||||
newStepName: 'newStep',
|
||||
customMessage: "test"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkConfiguration(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckConfigurationRemovedOrReplacedStages() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains configuration for the stage oldStage. " +
|
||||
"This stage has been removed. ")
|
||||
nullScript.commonPipelineEnvironment.configuration = [stages: [oldStage: [configKey: false]]]
|
||||
Map configChanges = [
|
||||
removedOrReplacedStages: [
|
||||
oldStage: []
|
||||
]
|
||||
]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkConfiguration(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckConfigurationParameterTypeChanged() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your pipeline configuration contains the configuration key configKeyOldType for the step testStep. " +
|
||||
"The type of this configuration parameter was changed from String to List. test")
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [testStep: [configKeyOldType: "string"]]]
|
||||
Map configChanges = [
|
||||
parameterTypeChanged: [
|
||||
configKeyOldType: [
|
||||
oldType: "String",
|
||||
newType: "List",
|
||||
steps: ["testStep"],
|
||||
customMessage: "test"]
|
||||
]
|
||||
]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkConfiguration(nullScript, configChanges)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckConfigurationRenamedNpmScript() {
|
||||
thrown.expect(hudson.AbortException)
|
||||
thrown.expectMessage("Your package.json file package.json contains an npm script using the deprecated name oldNpmScriptName. " +
|
||||
"Please rename the script to newNpmScriptName, since the script oldNpmScriptName will not be executed by the pipeline anymore. test")
|
||||
Map configChanges = [
|
||||
renamedNpmScript: [
|
||||
oldNpmScriptName: [
|
||||
newScriptName: "newNpmScriptName",
|
||||
customMessage: "test"]
|
||||
]
|
||||
]
|
||||
|
||||
LegacyConfigurationCheckUtils.checkConfiguration(nullScript, configChanges)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user