Bootstrap

jenkins 读取json文件_使用Jenkins写入工作区中的json文件 原创

Config File Provider Plugin不允许您将参数传递给配置文件.您可以使用任何脚本语言解决您的问题.我最喜欢的方法是使用

Groovy plugin.点击一个复选框“执行系统Groovy脚本”并粘贴以下脚本:

import groovy.json.*

// read build parameters

env = build.getEnvironment(listener)

environment = env.get('environment')

filename = env.get('filename')

// prepare json

def builder = new JsonBuilder()

builder environment: environment, filename: filename

json = builder.toPrettyString()

// print to console and write to a file

println json

new File(build.workspace.toString() + "\\job.json").write(json)

输出样本:

{

"environment": "ENV2",

"filename": "abc.txt"

}

;