diff --git a/test/groovy/CommonPipelineEnvironmentTest.groovy b/test/groovy/CommonPipelineEnvironmentTest.groovy index 1ac64ab0e..c64c49885 100644 --- a/test/groovy/CommonPipelineEnvironmentTest.groovy +++ b/test/groovy/CommonPipelineEnvironmentTest.groovy @@ -51,6 +51,14 @@ class CommonPipelineEnvironmentTest extends BasePiperTest { assertThat(nullScript.commonPipelineEnvironment.getValue('myList').key2, is('val2')) } + @Test + void testKeyRemoveFromMap() { + nullScript.commonPipelineEnvironment.setValue('myList', []) + nullScript.commonPipelineEnvironment.getValue('myList').add('item1') + nullScript.commonPipelineEnvironment.removeValue('myList') + assertThat(nullScript.commonPipelineEnvironment.getValue('myList'), is(null)) + } + @Test void testContainereMap() { nullScript.commonPipelineEnvironment.setContainerProperty('image', 'myImage') diff --git a/vars/commonPipelineEnvironment.groovy b/vars/commonPipelineEnvironment.groovy index c50fcc343..b0997292b 100644 --- a/vars/commonPipelineEnvironment.groovy +++ b/vars/commonPipelineEnvironment.groovy @@ -66,6 +66,10 @@ class commonPipelineEnvironment implements Serializable { valueMap[property] = value } + void removeValue(String property) { + valueMap.remove(property) + } + def getValue(String property) { return valueMap.get(property) }