Reputation: 1393
I am trying to get my head around groovy scripting to make some changes to a jenkins pipeline and I keep getting this error:
groovy.lang.MissingPropertyException: No such property: props for class: groovy.lang.Binding
I have tried declaring the variable with def but I still get the exception
pipeline {
agent any
stages {
stage('Build'){
steps {
script {
// env.application_servers = 'sl2o2xbar01;sl2o2xbar02'
def hb_parameters = []
if (env.application_servers.length() > 0) {
if (env.hb_job_params.length() > 0){
try {
//env.hb_job_params
/*
{
"sl2o2xbar01": {
"ENV": "DEV",
"dev_xbar_host": "sl2o2xbar01"
},
"sl2o2xbar02": {
"ENV": "DEV",
"dev_xbar_host": "sl2o2xbar0"
}
}
*/
def props = readJSON text: env.hb_job_params
//props = ['sl2o2xbar01':['ENV':'DEV', 'dev_xbar_host':'sl2o2xbar01'], 'sl2o2xbar02':['ENV':'DEV', 'dev_xbar_host':'sl2o2xbar02']]
def hb_job_application_servers = props.keySet()
echo "${props}"
} catch(e) {
echo "Caught: ${e} JSON not valid."
currentBuild.result = 'FAILURE'
}
}
application_servers_list = env.application_servers.split(';')
for( String application_server : application_servers_list ){
if (
env.application_services_list.contains('heartbeat_consumer') &&
props.get(application_server)
){
for ( param in props.get(application_server)) {
hb_parameters.add([$class: 'StringParameterValue', name: ${param.key}, value: ${param.value}])
}
echo hb_parameters
echo "triggering heartbeat_consumer build"
build job: "dvmt30-realm-monitor", wait: false, parameters: hb_parameters
}
}
}
}
}
}
}
}
Upvotes: 0
Views: 10724
Reputation: 346
Your definition of the variable props is inside the try-catch:
try {
def props = readJSON text: env.hb_job_params
...
}
But later, you try to use it in props.get(application_server)
and that variable does not exist anymore at that point
Upvotes: 0