Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-50269

Environment variables are silently coerced to String

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • 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.

            Unassigned Unassigned
            chrylis Christopher Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: