java - Jenkinsfile 写入 JSON 文件

标签 java json jenkins groovy jenkins-pipeline

在我的 Jenkinsfile 中,我尝试创建一个简单的 JSON 文件并将其写入工作区文件夹。

JSON文件的内容应该是:

{"people": {"name":"john","surname":"doe"}}

有什么想法吗?

最佳答案

知道了!

script {
          def someMap = [
              'name' : "john",
              'surname' : "doe"
          ]
          def json = new groovy.json.JsonBuilder()
          json "people": someMap
          def file = new File("$WORKSPACE/people.json")
          file.write(groovy.json.JsonOutput.prettyPrint(json.toString()))
        }

关于java - Jenkinsfile 写入 JSON 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53079638/

相关文章:

java - 为什么我的 AndroidHttpClient 在我调用 Execute 时不发送参数?

jenkins - Ansible jenkins_plugin 模块返回 "HTTP Error 403: No valid crumb was included in the request"

python - Numpy Pandas 安装失败,/dev/null 上存在沙箱冲突

java - Jenkins/Hudson Plot 插件 URL 构造不正确

java - Spark - 如何为每个执行器上下文创建不同的变量?

java - 在 Swing 中使用具有绝对布局的滚动条

java - 在 Eclipse Indigo 中绘制带圆角的 View

java - 使用 JaxRS 自定义 JSON 序列化

actionscript-3 - 无法在as3中为URLRequest设置 "Content-Type"

python - 如何根据其他实体的数据通过tastypie选择在django中创建或不创建实体?