Solved:多亏了里士满below answer号.我需要取消设置allgroovy.json.internal.LazyMap类型的存储映射,这意味着在使用后将变量envServersobject置零.

Additional:搜索此错误的人可能会有兴趣改用Jenkins管道步骤readJSON-查找更多信息here.


I am trying to use Jenkins Pipeline to take input from the user which is passed to the job as json string. Pipeline then parses this using the slurper and I pick out the important information. It will then use that information to run 1 job multiple times in parallel with differeing job parameters.

直到我将代码添加到"## Error when below here is added"以下,脚本才能正常运行.即使低于该点的代码也会自行运行.但是当组合起来的时候,我得到了下面的错误.

I should note that the triggered job is called and does run succesfully but the below error occurs and fails the main job. Because of this the main job does not wait for the return of the triggered job. I could try/catch around the build job: however I want the main job to wait for the triggered job to finish.

这里有人能帮忙吗?如果您需要更多信息,请告诉我.

Cheers

def slurpJSON() {
return new groovy.json.JsonSlurper().parseText(BUILD_CHOICES);
}

node {
  stage 'Prepare';
  echo 'Loading choices as build properties';
  def object = slurpJSON();

  def serverChoices = [];
  def serverChoicesStr = '';

  for (env in object) {
     envName = env.name;
     envServers = env.servers;

     for (server in envServers) {
        if (server.Select) {
            serverChoicesStr += server.Server;
            serverChoicesStr += ',';
        }
     }
  }
  serverChoicesStr = serverChoicesStr[0..-2];

  println("Server choices: " + serverChoicesStr);

  ## Error when below here is added

  stage 'Jobs'
  build job: 'Dummy Start App', parameters: [[$class: 'StringParameterValue', name: 'SERVER_NAME', value: 'TestServer'], [$class: 'StringParameterValue', name: 'SERVER_DOMAIN', value: 'domain.uk'], [$class: 'StringParameterValue', name: 'APP', value: 'application1']]

}

Error:

java.io.NotSerializableException: groovy.json.internal.LazyMap
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:569)
    at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
    at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
    at org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
    at org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
    at java.io.ObjectOutputStream.writeObject(Unknown Source)
    at java.util.LinkedHashMap.internalWriteEntries(Unknown Source)
    at java.util.HashMap.writeObject(Unknown Source)
...
...
Caused by: an exception which occurred:
    in field delegate
    in field closures
    in object [email protected]

推荐答案

我今天自己也遇到了这个问题,通过一些残酷的努力,我已经想出了如何解决它,以及可能的原因.

也许最好从原因开始:

Jenkins有一个范例,所有作业(job)都可以通过服务器重启来中断、暂停和恢复.为了实现这一点,管道及其数据必须是完全可序列化的——即它需要能够保存所有内容的状态.类似地,它需要能够序列化构建中节点和子作业(job)之间的全局变量状态,这就是我认为你和我正在发生的事情,也是为什么只有在添加额外的构建步骤时才会发生的事情.

For whatever reason JSONObject's aren't serializable by default. I'm not a Java dev so I cannot say much more on the topic sadly. There are plenty of answers out there about how one may fix this properly though I do not know how applicable they are to Groovy and Jenkins. See this post for a little more info.

How you fix it:

如果你知道怎么做,你就有可能以某种方式让JSONObject序列化.否则,您可以通过确保没有这种类型的全局变量来解决它.

try 取消设置objectvar或将其包装在方法中,使其作用域不是节点全局的.

Json相关问答推荐

boost::json::value 的大括号初始化将其从对象转换为数组

如何使用 jq 返回此 JSON 文件的“文本”字段?

如何在 Django 的模板语言中获取 json 键和值?

Jolt - 在同一级别添加时组合值的问题

json对象的大小? (以 KB/MB 为单位)

System.Text.Json 中是否可以进行多态反序列化?

消息通知产生“此内容无法显示”

在 ASP.NET Core 2.0 Web Api 中返回“原始”json

使用Angular 2 的 http.get() 从本地文件加载 json

无法安装站点:未检测到匹配的服务人员

使用可编码的值,有时是 Int,有时是 String

你如何在 Arrays of Arrays 上 OPENJSON

pandas.io.json.json_normalize 带有非常嵌套的 json

使用 jq 判断字符串是否是有效的 JSON

c# & newtonsoft 中的 JSON 日期和日期时间序列化

在 React 中导入 JSON 文件

来自 JSON 字符串的 Typescript `enum`

如何使用 Swift Decodable 协议解码嵌套的 JSON 结构?

TypeError:JSON 对象必须是 str,而不是 'bytes'

新的@angular/cli 版本中的文件 angular-cli.json 在哪里?