首页 > 解决方案 > Jenkins 更新后 readJSON 和 readYaml 停止在 Jenkins 中工作

问题描述

我已经在我的 Jenkins 中安装了 Pipeline Utility Steps 插件,并且我曾经使用readJSONreadYaml没有任何问题。

一个月后,当我尝试时,我都收到了以下错误

groovy.lang.MissingMethodException: No signature of method: Script1.readJSON() is applicable for argument types: (java.util.LinkedHashMap) values: [[file:/data/ecsnames/dev_ECSNames.json]]

readYaml 步骤的错误也类似。

我不确定它是如何突然停止工作的。我从我的一位队友那里得到的唯一信息是,几周前 Jenkins 已更新到 2.235.5 版本。

我使用了以下命令

def clstrndsrvcnme = readJSON file: "/data/ecsnames/dev_ECSNames.json"

谁能帮我这个?这个错误是什么意思?

更新*

所以我在JenkinsURL/script尝试了上述命令。有一个小 IDE 可以运行 groovy 脚本。我在那里进行各种调试。在那个位置,它抛出了错误。

但是当我从 Jenkins Job 运行相同的命令时,它工作得非常好,我能够从 Yaml 和 Json 读取值。所以我认为JenkinsURL/script无法使用 Pipeline Utility Scripts 插件。

我能够完成我的工作,但仍然想了解它为什么在这里失败JenkinsURL/script

标签: jsonjenkinsgroovyyamljenkins-pipeline

解决方案


我花了一天的大部分时间来解决同样的问题。这在脚本控制台中失败:

def jstring = '{"one":1, "two":2}'
def jobj = readJSON text: jstring

感谢您的帖子,我在测试管道中尝试了它并且它有效:

pipeline {
    agent any
    stages {
        stage('readjson') {
            steps {
                script {
                    def jstring = '{"one":1, "two":2}'
                    def jobj = readJSON text: jstring
                    echo jobj.toString()
                }
            }
        }
    }
} 
 [Pipeline] Start of Pipeline
 [Pipeline] node
 Running on Jenkins in C:\Program Files (x86)\Jenkins\workspace\readJSON
 [Pipeline] {
 [Pipeline] stage
 [Pipeline] { (readjson)
 [Pipeline] script
 [Pipeline] {
 [Pipeline] readJSON
 [Pipeline] echo
 {"one":1,"two":2}
 [Pipeline] }
 [Pipeline] // script
 [Pipeline] }
 [Pipeline] // stage
 [Pipeline] }
 [Pipeline] // node
 [Pipeline] End of Pipeline
 Finished: SUCCESS

我在 Jenkins Jira 中为这个插件记录了一个问题:https ://issues.jenkins.io/browse/JENKINS-65910

我会用 Jenkins 的任何回复来更新这篇文章。


推荐阅读