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

Config variable in global function is null

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Major Major
    • None
    • Jenkins 2.26
      workflow-cps-global-lib-plugin 2.4

      I am creating a global function as described here. Accessing the config-variable inside the function always returns null:

      def call(body) {
          // evaluate the body block, and collect configuration into the object
          def config = [:]
          body.resolveStrategy = Closure.DELEGATE_FIRST
          body.delegate = config
      
          body()
      
          echo "${config.name}"
          echo config.name
      
          echo "${config.foo}"
          echo config.foo
      }
      

      When called:

       myStep {
          name: 'linux-build'
          foo: "bar"
      }
      

      This prints null four times. Am I doing something wrong or is it a bug?

            Unassigned Unassigned
            bilke Lars Bilke
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: