比较jenkins管道中的两个列表



在我的管道中,我有两个列表,希望对其进行比较并相应地打印输出

1- println abc
[aaa, bbb, ccc]
2- println xyz
[bbb, ccc]

我需要将输出打印到一个文件中,如:

aaa not present in xyz
bbb present 
ccc preset

我尝试过的代码:

def test []
test = abc - xyz
println test
def abc = ['aaa', 'bbb', 'ccc']
def xyz = ['bbb', 'ccc']
//simple 
println 'present in xyz: ' + abc.intersect(xyz).join(', ')
println 'not present in xyz: ' + abc.minus(xyz).join(', ')
//with for-each
for(i in abc){
if(i in xyz) println "present in xyz: $i"
else println "not present in xyz: $i"
}

您可以尝试以下方法:

abc.each{valueOne ->
doesValueExist = false
xyz.each{ valueTwo->
if(valueOne.equals(valueTwo}{
doesValueExist = true
} 
}
if(doesValueExist){
echo "${valueOne} is present"
} else { 
echo  "${valueOne} is not present"
}
}

最新更新