根据 Jenkins 中的条件从数组中删除一个项目
Remove an item from array based on condition in Jenkins
我正在尝试根据条件从数组中删除一个项目。如果一个字符串包含一个特定的子字符串,所有这些项目都应该从数组中删除。从下面的数组中,我需要删除所有带有字符串 '-oh-'
的项目
下面是我的代码
myArray = [
"Item1",
"Item2",
"Item3",
"test-oh-test",
"Item4",
"demo-oh-test",
"Item5",
"val-oh-trial"
]
if(myArray.contains('-oh-')
{
myArray.remove(/*Need the syntax here*/)
}
这将删除所有匹配的元素:
myArray = [
"Item1",
"Item2",
"Item3",
"test-oh-test",
"Item4",
"demo-oh-test",
"Item5",
"val-oh-trial"
]
myArray.removeAll {it -> it.contains("-oh-")}
assert myArray == ["Item1", "Item2", "Item3", "Item4", "Item5"]
我正在尝试根据条件从数组中删除一个项目。如果一个字符串包含一个特定的子字符串,所有这些项目都应该从数组中删除。从下面的数组中,我需要删除所有带有字符串 '-oh-'
的项目下面是我的代码
myArray = [
"Item1",
"Item2",
"Item3",
"test-oh-test",
"Item4",
"demo-oh-test",
"Item5",
"val-oh-trial"
]
if(myArray.contains('-oh-')
{
myArray.remove(/*Need the syntax here*/)
}
这将删除所有匹配的元素:
myArray = [
"Item1",
"Item2",
"Item3",
"test-oh-test",
"Item4",
"demo-oh-test",
"Item5",
"val-oh-trial"
]
myArray.removeAll {it -> it.contains("-oh-")}
assert myArray == ["Item1", "Item2", "Item3", "Item4", "Item5"]