【发布时间】:2019-07-26 08:17:00
【问题描述】:
我正在尝试通过 readYaml 从 yaml 获取地图和数组列表等对象 进入变量 'configObj' 并将 'configObj' 传递给 vars/ 文件夹中的 groovy 脚本以进行提取。来自“configObj”的映射和数组。 这是在 jenkins DSL Pipeline 和共享库中
我尝试了 readYaml 并将 yaml 对象传递给 groovy 脚本。发现在 groovy 脚本中收到的对象为 NULL。
//-----Jenkinsfile------
@Library('Library')_
configObj = ""
pipeline{
...
script{
configObj = readYaml file : 'config/TestbedSpecificConfig.yaml'
echo("${configObj.setup_steps}")
flowManager operation : "INI_ZN", config : configObj
}
...
}
//---------------Yaml-----------------
---
-
setup_steps:
- stop_tomcat
- featurestress_backup
- update_release_type
- update_branch_name
- update_testcase
- snapshotInfo:
- snapshot_name: vSphere65U2
- infra_ip: 10.173.124.1
- esxi_base_name: vEsxi-173-
- esxi_start_index: 101
- esxi_end_index: 200
- revert_appliances :
- Embedded_60_65_Upgrade: vc65
- delete_target_vc :
- Embedded_65_67_Upgrade
- Embedded_67_68_Upgrade
- Embedded_65_68_Upgrade
- Embedded_60_68_Upgrade
- extpsc.st.local
//------------flowManager------------
def call(Map propertes){
FolderUtils futils = new FolderUtils(this)
CliUtils cutils = new CliUtils(this)
RestUtils rutils = new RestUtils(this)
TestBedUtils tutils = new TestBedUtils(this)
WebAppUtils wutils = new WebAppUtils(this)
TemplateHelper thelpar = new TemplateHelper(this)
switch("${propertes.operation}") {
case "INI_ZN":
log.info("OPERATION : ${propertes.operation}" )
log.info("CONFIG : ${properties.config}") <=== This prints NULL
wutils.init(properties.config)
break
...
}
}
预期
在 groovy 脚本中获取 configObj
预计将 setup_setps 的值访问为:
configObject.setup_steps.each{ echo("${it}")}
类似地映射 yaml 中 snapShotInfo 表示的对象。
实际:
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.String setup_steps
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.unclassifiedField(SandboxInterceptor.java:425)
at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:409)
at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:289)
【问题讨论】:
标签: jenkins yaml jenkins-pipeline shared-libraries dsl