jenkins - Groovy:如何加入地图值/为什么结果不一致?
问题描述
为什么以下 Groovy 脚本:
def d = ["foo":"lorem", "bar":"ipsum", "baz":"dolor"]
def j = d.inject([]) { result, e -> result += e.value }.join()
...导致所需的值j
:loremipsumdolor
在https://groovyconsole.appspot.com/但从我的 Jenkinsfile 运行时会导致以下错误:
java.lang.NullPointerException: Cannot invoke method join() on null object
我的 Jenkins 服务器正在运行 Groovy 2.4.12。
我不知道,也不清楚如何确定在https://groovyconsole.appspot.com/上运行的 Groovy 版本。
上面的代码灵感来自https://blog.mrhaki.com/2009/09/groovy-goodness-using-inject-method.html
为什么上述脚本在从 Jenkins 运行时会导致错误,以及实现所需功能的另一种优雅/Groovy 惯用方式是什么:加入所有地图值?
解决方案
推荐阅读
- ruby-on-rails-5 - Rails - 如何获得参数总数
- google-bigquery - BigQuery 的 FARM_FINGERPRINT 如何表示 64 位 *unsigned* int?
- php - 将文件作为 varbinary 数据类型插入 mysql 数据库
- windows - 使用 powershell 更改任务栏位置并自动隐藏 Windows 10 build 14393
- ios - 在 Alamofire 请求中发送请求正文数组
- security - 什么是容器?和gVisor?
- python - 通过多个分隔符拆分并保留分隔符
- java - RSS 提要应用程序在不同的 Android 版本上无法正常工作
- clojure - 如何打破clojure宏中的递归条件?
- java - Json, Java, Parsing(如何只获取json的一部分