[英]Unable to access yaml objects after reading yaml from jenkins pippeline
我试图通过readYaml从yaml中获取诸如map和array list之类的对象进入变量'configObj'并将'configObj'传递给vars /文件夹中的groovy脚本以进行提取。 从“ configObj”映射和排列。 这在带有共享库的詹金斯DSL管道中
我尝试了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)
发现该调用实现除了一个类型为LinkedHashList的参数外。 为了克服这一要求。
詹金斯档案
@Library('Library')_
configObj = ""
pipeline{
...
script{
configObj = readYaml file : 'config/TestbedSpecificConfig.yaml'
flowManager config : configObj
}
...
}
vars / flowManager,groovy
def call(def config){
switch("${STAGE_NAME}"){
case "Pipeline Initialization":
wutils.initialization(config)
break
}
}
这种逻辑对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.