jenkins - 如何在 Jenkinsfile groovy map 中定义和获取/放置值
问题描述
我在下面有这个 Jenkinsfile。我正在尝试获取地图的密钥,但我得到了"java.lang.NoSuchMethodError: No such DSL method 'get' found among steps"
. 有人可以帮我解决这个问题吗?
def country_capital = {
[Australia : [best: 'xx1', good: 'xx2', bad: 'xx3'],
America : [best: 'yy1', good: 'yy2', bad: 'yy3']]
}
pipeline {
agent any
stages {
stage('Test Map') {
steps {
script {
echo country_capital.get('Australia')['best']
}
}
}
}
}
解决方案
您可以使用这种方式获得价值
def country_capital = [
Australia: [
best: 'xx1',
good: 'xx2',
bad: 'xx3'
],
America: [
best: 'yy1',
good: 'yy2',
bad: 'yy3'
]
]
pipeline {
agent any
stages {
stage('Test Map') {
steps {
script {
echo country_capital['Australia'].best
}
}
}
}
}
// Output
xx1
推荐阅读
- java - WorkManager 约束(setRequiresCharging)在模拟器上不起作用
- java - 如何在我的方法中获取已经存在的文件(在我的计算机上)并将其转换为 InputStream?
- python - 什么相当于 Makefile 对 SConstruct 的包含?
- asp.net - 尝试路由参数以捕获家庭控制器上的所有索引操作
- hibernate - 使用 Spring boot 时的两个版本的 Hibernate
- docker - 连接到远程 Docker 守护进程
- facebook - 使用 Facebook graph api 的网站加载速度非常慢
- hadoop - hadoop 3.1.2 ./start-all.sh 错误,意外标记 `<' 附近的语法错误
- npm - Gulp 4 任务未与并行/串行同步运行
- typescript - 如何从嵌套对象中选择类型?