1

このリストを groovy スクリプトに転置したいと考えています。2つのリストがあります

result_name = ["API (例)","管理ポータル (例)","Component1","Component2",]

result_ids = ["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]

list[0][0], list[1][1].... のような出力を期待しています。例:

API (example) 3wrhs4vp3sp5
Management Portal g2828br1gzw9
Component1 68pnwhltxcq0
Component2 fy8g2nvvdg15

私はこれを使用して試しています

def result = [[result_name], [result_ids]].transpose()

しかし、結果は次のとおりです。

結果: [[["API (例)","管理ポータル (例)","Component1","Component2",], ["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]]]

編集:質問のサンプルコードを更新しました:

proc1 = ['/bin/bash', '-c', "curl https://api.statuspage.io/v1/pages/lbh0g6b5mwnf/components?api_key=<key>"].execute()
proc2 = ['/bin/bash', '-c', "grep -Po '\"name\": *\\K\"[^\"]*\"'| tr '\n' ', '"].execute()
proc3 = ['/bin/bash', '-c', "curl https://api.statuspage.io/v1/pages/lbh0g6b5mwnf/components?api_key=<key>"].execute()
proc4 = ['/bin/bash', '-c', "grep -Po '\"id\": *\\K\"[^\"]*\"'| tr '\n' ', '"].execute()

all_name = proc1 | proc2
all_ids = proc3 | proc4
def result_name = [all_name.text]
def result_ids = [all_ids.text]

println result_name
println result_ids

def result = [result_name, result_ids].transpose()

結果

["API (example)","Management Portal (example)","Component1","Component2",]
["3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]
Result: [["API (example)","Management Portal (example)","Component1","Component2",, "3wrhs4vp3sp5","g2828br1gzw9","68pnwhltxcq0","fy8g2nvvdg15",]]
 
4

2 に答える 2

0

私自身の質問に答えます。

いくつかのデバッグの後、リストに単一の文字列が含まれていることに気付きました。そのため、split() はその奇妙な入力を予期していませんでした。newstr以下のコードを入力してから分割することで、最初の文字列を出力できました。

all_name = proc1 | proc2
all_ids = proc3 | proc4
    
result_name = [all_name.text]
result_ids = [all_ids.text]

newstr = result_name[0]
result_newstr = newstr.split(',')

newids = result_ids[0]
result_newids = newids.split(',')

def aa = []
for(int i = 0;i< result_newstr.size(); i++) {
    a = result_newstr[i].concat(" ").concat(result_newids[i])
  aa.add(a)
}
return aa

これにより、次の結果が得られます。

"API (example)" "3wrhs4vp3sp5"
"Management Portal (example)" "g2828br1gzw9"
"Component1" "68pnwhltxcq0"
"Component2" "fy8g2nvvdg15"
于 2021-08-24T12:57:22.553 に答える