-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major
-
Component/s: pipeline
-
None
-
Environment:Jenkins: 2.492.2
OS: Linux - 5.15.167.4-microsoft-standard-WSL2
Java: 17.0.14 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)
installed plugins in attachment
Discussion started here https://community.jenkins.io/t/final-keyword-doesnt-work-properly-in-pipeline/33172
Example pipeline:
pipeline {
agent any
stages {
stage('Hello') {
steps {
script {
final String str = "1"
str = "2"
echo str
}
}
}
}
}
For some reason final doesn't work, i.e. it doesn't create a constant and the variable value can be changed.
The pipeline output is 2.
The behavior in the Shared library is similar for variables with local scope, but if you declare a class field as final and try to change it in one of the methods, you get:
hudson.remoting.ProxyException: groovy.lang.ReadOnlyPropertyException: Cannot set readonly property: myProperty for class: mainpackage.MyClass