1
我試圖在jenkins作業中構建json文件。如何在for循環內jenkins中創建json文件
我有一個回購清單和每個回購分行清單。我想獲取這些數據並用它構建一個json文件。
最終的結果應該像
[
{
"name": "repoName",
"branches" :
[
"name" : "branchName",
"name" : "branchName2"
]
},
{
"name": "repoName2",
"branches" :
[
"name" : "branchName",
"name" : "branchName2",
"name" : "branchName3",
]
}
]
repoName和BRANCHNAME都來自瓦爾。
我的代碼看起來像這樣
script {
node{
unstash 'build'
env.WORKSPACE = pwd()
def buildConfig = load "GenerateBuildSelections.Groovy"
def repos = buildConfig.GetListOfRepos("${env.WORKSPACE}/Repos.json")
for(i = 0; i < repos.size(); i++){
def repoName = repos[i]
httpRequest acceptType: 'APPLICATION_JSON', authentication: '********-****-****-****-************', consoleLogResponseBody: true, contentType: 'APPLICATION_JSON', outputFile: "branches_${repoName}.json", responseHandle: 'NONE', url: "https://api.github.com/repos/GenesisGaming/${repoName}/branches"
env.WORKSPACE = pwd()
def branches = buildConfig.GetListOfBranches("${env.WORKSPACE}/branches_${repoName}.json")
//How do I save the Repo name with the branches here without overwriting the builder everytime
}
}
}
我希望能夠給每個回購保存分支機構相同的JSON列表。我不知道如何做到這一點,而不是每次都覆蓋它。
我不明白你的意思是「沒有改寫建造者」。你能否包括你試過的代碼和產生的錯誤文件?是文件只包含一個回購的問題?如果是這樣,我認爲你需要初始化一個HashMap,在迭代時填充它,然後在最後將它轉儲到json。 – burnettk
謝謝,這有助於我能夠使用hashmap –