json - Jenkins 更新后 readJSON 和 readYaml 停止在 Jenkins 中工作
问题描述
我已经在我的 Jenkins 中安装了 Pipeline Utility Steps 插件,并且我曾经使用readJSON和readYaml没有任何问题。
一个月后,当我尝试时,我都收到了以下错误
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。
解决方案
我花了一天的大部分时间来解决同样的问题。这在脚本控制台中失败:
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 的任何回复来更新这篇文章。
推荐阅读
- google-chrome - 如何在打开和关闭的 Firefox 窗口之间循环?
- python - 如何计算数据框两列中元素的出现次数?
- xml - C# 中的 LINQ/XML - 使用 XPathEvaluate 返回 XPATH 计数
- node.js - Sendgrid API 密钥未从 env 变量中正确读取
- generics - 有没有办法在 VHDL 中从通用设置多个端口?
- html - Spring boot 从另一个控制器修改一个控制器中定义的 model.attribute 值
- drupal-7 - Drupal 7导出Excel无法打开文件
- python - 如何获得大于 255 的前 100 个素数幂?
- urbancode - 除非执行了另一个组件进程,否则 UrbanCode Deploy 父请求属性不可用
- web - 使用 Icecast 和 Drupal 创建实时音频流服务