-
Bug
-
Resolution: Unresolved
-
Minor
-
None
A previous issue (JENKINS-41718) noted problems with non-String environment variables in the pipeline. This seems to have been "resolved" by coercing environment variables to String (e.g., false becomes "false"). This causes problems when interacting with the CPS compiler and the sandbox. Example:
customStep.groovy
def call(boolean yesOrNo) { if(yes) { // do things } }
Jenkinsfile
pipeline { environment { YES_OR_NO = false } stages { stage('foo') { steps { customStep(YES_OR_NO) } } } }
error
org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method groovy.lang.GroovyObject invokeMethod java.lang.String java.lang.Object (org.jenkinsci.plugins.workflow.cps.CpsClosure2 customStep java.lang.String)
There may not be a clean, uniform way to resolve this, but it's a nasty landmine that at least needs to be documented if it can't be fixed.
Yeah, environment variables in Pipeline (or, for that matter, in Freestyle) are always coerced to strings. Not sure where in the docs this should be clarified yet, but I'm throwing it in my queue to do so.