[英]Unable to access yaml objects after reading yaml from jenkins pippeline
I am trying to get objects like map and array list from yaml via readYaml Step in to variable 'configObj' and pass 'configObj' to groovy script in vars/ folder for extracting . 我试图通过readYaml从yaml中获取诸如map和array list之类的对象进入变量'configObj'并将'configObj'传递给vars /文件夹中的groovy脚本以进行提取。 Map and array from 'configObj'.
从“ configObj”映射和排列。 This is in jenkins DSL Pipeline with Shared Library
这在带有共享库的詹金斯DSL管道中
I tried readYaml and pass the yaml object to groovy script. 我尝试了readYaml并将yaml对象传递给groovy脚本。 Object received in groovy script was found to be NULL.
发现在groovy脚本中接收到的对象为NULL。
//------Jenkinsfile--------- // ------ Jenkinsfile ---------
@Library('Library')_
configObj = ""
pipeline{
...
script{
configObj = readYaml file : 'config/TestbedSpecificConfig.yaml'
echo("${configObj.setup_steps}")
flowManager operation : "INI_ZN", config : configObj
}
...
}
//---------------Yaml----------------- // --------------- 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------------ // ------------ 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
...
}
}
Expected 预期
to get configObj in groovy script Expected to access values of setup_setps as : configObject.setup_steps.each{ echo("${it}")} 在groovy脚本中获取configObj预期以以下方式访问setup_setps的值:configObject.setup_steps.each {echo(“ $ {it}”)}
Similarly map objests represented by snapShotInfo in yaml. 类似地,映射由yaml中的snapShotInfo表示的对象。
Actual : 实际:
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)
Found that call implementation excepts one parameter of type LinkedHashList. 发现该调用实现除了一个类型为LinkedHashList的参数外。 To overcome this requirement.
为了克服这一要求。
jenkinsfile 詹金斯档案
@Library('Library')_
configObj = ""
pipeline{
...
script{
configObj = readYaml file : 'config/TestbedSpecificConfig.yaml'
flowManager config : configObj
}
...
}
vars/flowManager,groovy vars / flowManager,groovy
def call(def config){
switch("${STAGE_NAME}"){
case "Pipeline Initialization":
wutils.initialization(config)
break
}
}
This logic works fine for me. 这种逻辑对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.