-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins LTS 2.46.3
Pipeline v2.5
According to the Jenkins docs, one should be able to define getters and setters for global variables in shared pipeline scripts to manipulating fields. This does not seem to work correctly. Take the following example which is a slight variation on the example from the docs:
// tmp_shared/vars/acme.groovy def setName(value) { echo "Setting name to $value" this.@name = value } def getName() { echo "Getting name of " + this.@name return this.@name }
// Pipeline script @Library ('tmp_shared') _ acme.name = 'Alice' // should print "Setting name to Alice" to the console def tmp = acme.name // should print "Getting name of Alice" to the console
I'd expect the output from this simple test to look something like this:
... Setting name to Alice Getting name of Alice ...
However I see no console output whatsoever. This indicates that the getter and setter methods are not being invoked at all when defined in the Groovy vars scripts for a shared pipeline library.
- relates to
-
JENKINS-31484 Endless loop in DefaultInvoker.getProperty when accessing field via getter/setter without @
-
- Resolved
-
-
JENKINS-38021 Accessing unset global variable cause master to hang
-
- Resolved
-
I probably should point out this slight variation on the problem outlined above which behaves slightly differently. Consider the following example scripts:
The output from this example looks as follows:
It's worth noting that while the getter is called when accessing the field before the value is explicitly set, it is not called after the field is explicitly set (ie: we don't see the "In getter..." output before the "Shared name is now Jane" message). Not sure how / why the behavior would be subtly different in this case but I thought it might be related to the underlying problem.