-
Type:
Bug
-
Resolution: Not A Defect
-
Priority:
Major
-
Component/s: workflow-cps-plugin
-
Environment:Jenkins 2.132
hasProperty does not work as expected when used on the this-context of a pipeline script. It should return true for existing parameter and false for non-existing parameter but it returns null in both cases. getProperty in contrast works as expected.
Steps to reproduce:
 Create parameterized Pipeline job with following parameters:
- string parameter myProperty and value "present" and the following pipeline script
// Pipeline Script pipeline { agent none stages { stage('HasPropertyTest') { steps { script { echo "Value of 'myProperty': ${getProperty("myProperty")}" echo "Got: ${hasProperty("myProperty")} - expected ${true}" try { echo "Value of 'missingProperty' ${getProperty("missingProperty")}" } catch (MissingPropertyException) { echo "Parameter 'missingProperty' does not exist." } echo "Got: ${hasProperty("missingProperty")} - expected ${false}" if(hasProperty("myProperty")) { // success } else { error "No Property: myProperty" } } } } } }
- No Groovy Sandbox
Got Output:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (HasPropertyTest)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Value of 'myProperty': present
[Pipeline] echo
Got: null - expected true
[Pipeline] echo
Parameter 'missingProperty' does not exist.
[Pipeline] echo
Got: null - expected false
[Pipeline] error
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
ERROR: No Property: myProperty
Finished: FAILURE
Expected Output:
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] stage
[Pipeline] { (HasPropertyTest)
[Pipeline] script
[Pipeline] {
[Pipeline] echo
Value of 'myProperty': present
[Pipeline] echo
Got: true - expected true
[Pipeline] echo
Parameter 'missingProperty' does not exist.
[Pipeline] echo
Got: false - expected false
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] End of Pipeline
Finished: SUCCESS
Â