上下文: 我正在寫一個jenkins文件,我想在其中讀取Input_params.txt
文件,搜索關鍵字,然後將關鍵字的值打印到一個數組然後打印數組的每個元素。Groovy:使用groovy從文本文件讀取一行到一個數組
輸入則params的(格式爲"KEY:VALUE"
)文件中的內容是:
sh> cat Input_params.txt
SOME_DETAILS:1234-A0;1456-B1;2456-B0;3436-D0;4467-C0
步驟-1:存放SOME_DETAILS在一個陣列:
Integer[] testArray = ["1234-A0", "1456-B1", "2456-B0" , "3436-D0" , "4467-C0"]
步驟-2:打印的元素數組順序。例如:
testArray.each {
println "chip num is ${it}"
}
示例代碼:
println ("Check if the "Key:Value" is present in the Input_params.txt \n");
if (new File("$JobPath/Input_params.txt").text?.contains("SOME_DETAILS"))
{
println ("INFO: "Key:Value" is present in the info_file.txt \n");
>>>>> Code to write the "value" of line with key "SOME_DETAILS" into an array here.. <<<<<
}
我需要以書面形式寫與關鍵「SOME_DETAILS」到一個數組行的「價值」的代碼的幫助。
是同樣的問題? https://stackoverflow.com/questions/44158849/groovy-regex-to-filter-out-keyvalue-pair-and-store-in-an-array/44160636#44160636 – daggett
嗨@dagett,這裏的問題略有不同.. – Yash