Pipeline as library doesn't see variables outside pipeline block

This issue is archived. You can view it, but you can't modify it. Learn more

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

            Assignee:
            Liam Newman
            Reporter:
            Sean
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Archived: