1
jenkinsジョブでjsonファイルを作成しようとしています。forループ内のjenkinsでjsonファイルを作成する方法
私は各リポジトリのブランチのリストを持つreposのリストを持っています。私はこのデータを取得し、それを使ってjsonファイルを作成したいと思います。
最終結果は
[
{
"name": "repoName",
"branches" :
[
"name" : "branchName",
"name" : "branchName2"
]
},
{
"name": "repoName2",
"branches" :
[
"name" : "branchName",
"name" : "branchName2",
"name" : "branchName3",
]
}
]
repoNameのように見えるとbranchName両方VARSから来る必要があります。
私のコードは、私が同じJSONに枝のすべてのリストを各レポを保存できるようにしたい、この
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
}
}
}
のように見えます。私は毎回それを上書きすることなくこれを行う方法を理解できません。
"ビルダーを上書きしない"という意味を理解できません。試したコードとその結果として間違ったファイルを含めることはできますか?ファイルに1つのレポだけが含まれているという問題はありますか?もしそうなら、あなたはHashMapを初期化し、反復しながらそれを移入し、最後にそれをjsonにダンプする必要があると思います。 – burnettk
ありがとうございました。私はハッシュマップを使って作業することができました –