jenkinsci / jenkinsci/workflow-cps-plugin

[JENKINS-45834] Setters for shared pipeline scripts not getting called

Open
#1,340 6 comments 0 reactions 0 assignees View on GitHub
component:workflow-cps-plugin imported-jira-issue priority:minor resolution:unresolved
Dominant language
Java
Stars
186
Forks
213
Avg merge
12h 12m
Merged PRs (30d)
8

Description

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. 

 

---
Originally reported by leedega, imported from: Setters for shared pipeline scripts not getting called


  • status: Open
  • priority: Minor
  • component(s): workflow-cps-plugin
  • resolution: Unresolved
  • votes: 2
  • watchers: 6
  • imported: 2025-12-07

Raw content of original issue

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. 

 

environment

```
Jenkins LTS 2.46.3

Pipeline v2.5
```

Contributor guide

Open the contributing guide

Research direction

Start with the shared-library example in tmp_shared/vars/acme.groovy and the accompanying Pipeline script, then compare its behavior with the Jenkins shared-libraries documentation. Reproduce the example on the reported environment and trace why the getter and setter calls produce no console output; done means the expected setter and getter messages appear.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
ci-cd, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.