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

Pipeline as library doesn't see variables outside pipeline block

XMLWordPrintable

      This is continuation of problem described in comment JENKINS-37984#comment and JENKINS-64846

      File vars/lib.groovy

      import com.company.Devices
      def call(Map settings) {
      pipeline {
        agent none        
        stages {
          stage('CI pipeline') {
            when { 
              expression { 
                return Devices.exists("${device[PLATFORM]}_${settings.projectKey}")
              }
            }
            steps {
              script {
                Devices.create_simulator(name: "${device[PLATFORM]}_${settings.projectKey}", os_version: '14-2', device: 'iPhone-11')
              }
            }
          }
        }
      }

      File Jenkinsfile

      #!groovy
      library 'library'
      lib(
          projectKey: 'key'
      )
      

       

      This fails to identify the call parameters since 1.8.0, and can't have @Field specified because it's inside a function.

      Also:   hudson.remoting.ProxyException: groovy.lang.MissingPropertyException: No such property: settings for class: lib
      		at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
      		at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:458)
      		at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.getProperty(DefaultInvoker.java:39)
      		at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      

      Parameters like: `SCRIPT_SPLITTING_TRANSFORMATION` & `SCRIPT_SPLITTING_ALLOW_LOCAL_VARIABLES` were not defined at all, as experimental feature supposed to be disabled by default.

       

      Expected result:

      • Users are not forced to fix each pipeline (and branch) variable with `@groovy.transform.Field` annotation
      • Pipelines with matrix (and latest `pipeline-model-definition` plugin) is continue support of variables, defined outside of `pipeline`
      • Experimental features without breaking changes

            bitwiseman Liam Newman
            smillernl Sean
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: