I was referring to the closure for the httpPost command, however the same principle applies to exception handler (try/catch) blocks. Here's a few examples...
httpPost(paramsMode) { response ->
def someVariable = "Test 123"
log.trace someVariable // This outputs Test 123
}
log.trace someVariable // Outputs nothing because it was defined within the closure.
Here's an example, taking the definition up a level and adding an exception handler...
try {
def someVariable = "Test 123"
httpPost(paramsMode) { response ->
log.trace someVariable // This outputs Test 123 because it's in scope of the try block
}
log.trace someVariable // This outputs Test 123 because it's in scope of the try block
} catch (e) {
log.trace someVariable // Outputs nothing because it was defined within the try block.
}
log.trace someVariable // Outputs nothing because it was defined within the try block.
And finally where I suggested he define it...
def someVariable = "Test 123"
try {
httpPost(paramsMode) { response ->
log.trace someVariable // This outputs Test 123 because it's in scope of the method
}
log.trace someVariable // This outputs Test 123 because it's in scope of the method
} catch (e) {
log.trace someVariable // This outputs Test 123 because it's in scope of the method.
}
log.trace someVariable // This outputs Test 123 because it's in scope of the method
Hopefully this helps to clarify how scoping can raise unexpected issues like this..
Having that in Camelcase wouldn't affect that, would it? (I'm still not 100% clear on when that is necessary and when it isn't. If one doesn't work I just try the other. )