groovy 如何在Jenkins管道中从变量读取JSON?

0mkxixxg  于 2022-11-01  发布在  Jenkins
关注(0)|答案(1)|浏览(179)

enter image description here

// @Library('dxy-shared-library') _

管道{代理任意//参数{ //文本默认值:“""{“a”:1,“b”:[1,2,3]}“"”,名称:“元”// }

stages {
    stage('Hello') {
        steps("Git Checkout") {
            echo 'Hello World'
            echo "${meta}"
            script {
                def props = readJSON text: meta;
                println props
            }
        }
    }
}

}

hudson.remoting.ProxyException: net.sf.json.JSONException: Invalid JSON String
at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:143)
at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:103)
at net.sf.json.JSONSerializer.toJSON(JSONSerializer.java:84)
at org.jenkinsci.plugins.pipeline.utility.steps.json.ReadJSONStepExecution.doRun(ReadJSONStepExecution.java:87)
at org.jenkinsci.plugins.pipeline.utility.steps.AbstractFileOrTextStepExecution.run(AbstractFileOrTextStepExecution.java:29)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)

已完成:失败

vsmadaxz

vsmadaxz1#

管道{任意代理

stages {
    stage('Hello') {
        steps("Git Checkout") {
            echo 'Hello World'
            echo "${meta}"
            script {
                def props = readJSON text: meta.replace("'", "");
                println props
            }
        }
    }
}

}

相关问题