我正在为 Jenkinsfile 编写一个 GROOVY 脚本来执行以下操作:
Step-1:读取输入文件info_file.txt
。info文件的内容如下:
sh> cat info_file.txt
CHIP_DETAILS:1234-A0;1456-B1;2456-B0;3436-D0;4467-C0
第2步:删除后缀等CHIP_DETAILS
后将其存储在数组中。-A0,-B1
例如:
Integer[] testArray = ["1234", "1456", "2456" , "3436" , "4467"]
Step-3:按顺序打印数组的元素。例如:
testArray.each {
println "chip num is ${it}"
}
我编写了一个小代码来测试CHIP_DETAILS
输入文件中是否存在“密钥”并且它正在工作。但是我发现很难编写正则表达式来删除后缀(-A0,-B1
等)并将相应的值存储在数组中。代码如下:
stage('Read_Params')
{
steps
{
script
{
println ("Let's validate and see whether the "Key:Value" is present in the info_file.txt\n");
if ( new File("$JobPath/Inputparams.txt").text?.contains("CHIPS_DETAILS"))
{
println ("INFO: "Key:Value" is present in the info_file.txt \n");
>>>>> proceed with Step-1, Step-2 and Step-3... <<<<<
}
else
{
println ("WARN: "Key:Value" is NOT present in the info_file.txt \n");
exit 0;
}
}
}
}
提前感谢您的帮助!