我有一份 jenkins 作業,其中一部分將轉到 azure blob 中的檔案并獲取資訊“https://bla.blob.core.windows.net/data/ips.txt”,內容是
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
id 喜歡 jenkins 從中構建一個字串陣列并將其傳遞給另一個命令。問題是當我使用:
def response = httpRequest 'https://blabla.blob.core.windows.net/data/ips.txt'
然后嘗試將回應傳遞給另一個命令,因為資料是一個大字串,所以出現問題:
1.1.1.1\n2.2.2.2\3.3.3.3...
如何將其轉換為字串陣列?
uj5u.com熱心網友回復:
拆分方法
groovy 中的字串有一個 split 方法。您可以將您的字串拆分為一個串列,如下所示
def str = "1.1.1.1\n2.2.2.2\n3.3.3.3"
def strArr = str.split("\n") // this is what you want to send
// Printing the array so you can see it appropriately split
strArr.each{
println it
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/348755.html
標籤:詹金斯
下一篇:種子作業無法決議構建用戶變數插件
